Chef Needs Candies
All submissions for this problem are available.
Chef recently worked in a Candy Store. He has decided he will start his own Candy Store. But he need suppliers of different candies, which will help him run his shop. He has N friends who are suppliers of candies, who'll support him. But when these suppliers tie up with one another, there is a chance of extracting more candies due to friendship among them.
Each supplier will give Xi candies to Chef. When Xith supplier combines with any other Xjth supplier and if binary AND of the candies are greater than or equal to the supplier in tie with lesser supply of candies, then Chef will choose this tie of suppliers to extract extra candies. Calculate maximum number of candies Chef can get to run his shop.
The first line of the input contains an integer T denoting the number of test cases. Each test case T starts with a number N denoting the number of suppliers. Next line consists of X1, X2,..., XN denoting the number of candies which a supplier can supply.
For each test case, print the maximum number of candies Chef will obtain at the end to run his new shop.
- 1 ≤ T ≤ 100
- 1 ≤ N ≤ 100000
- 1 ≤ Xi ≤ 100000
Input: 1 4 5 4 7 9 Output: 38
Example Case 1: Each supplier will supply for sure the minimum candies which is given which makes 5+4+7+9 = 25. Along with that, ties between (5 and 4, 5 and 7), (4 and 7) will add to sum of 25. This makes final total 25 + (4 + 5) + (4) = 38 candies in total.
|Time Limit:||2 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS|
Fetching successful submissions