CareerCup Find top k values (asec) which can either be the number from the array A

来源:互联网 发布:淘宝应用开发者平台 编辑:程序博客网 时间:2024/04/28 06:22
You are given an array A of k values which contain int values in sorted (asec) order. Find top k values (asec) which can either be the number from the array A, or sum of any two numbers from A or sum of any three numbers from A. So, if A's values are represented as : a1,a2,...,ak , the possible numbers can be: a(i), a(i)+a(j), a(i)+a(j)+a(l) for any i,j,l < k 

Ex: A[7] = {3,4,5,15,19,20,25} 

output B[7] = {3,4,5,(3+4),(3+5),(4+5),(3+4+5)}

-------------------------------------------------


Get the first k values from A , then name as heap1

Get the first k values from sum of any two numbers from A, then name as heap2

Get the first k values from sum of any three numbers from A, then name as heap3

Merge heap1, heap2, heap3






0 0
原创粉丝点击