Solutions are presented as using the least memory and the fastest execution time. It also takes the top
10 most recent solutions from each language. If you want to limit to a specific index, click the
"Solved" button and go to that problem.
Problems
B'You have a bag of size n . Also you have m boxes. The size of i -th box is a_i , where each a_i is an integer non-negative power of two. You can divide boxes into two parts of equal size. Your goal is to fill the bag completely. For example, if n = 10 and a = [1, 1, 32] then you have to divide the box of size 32 into two parts of size 16 , and then divide the box of size 16 . So you can fill the bag with boxes of size 1 , 1 and 8 . Calculate the minimum number of divisions required to fill the bag of size n . The first line contains one integer t ( 1 <= t <= 1000 ) -- the number of test cases. The first line of each test case contains two integers n and m ( 1 <= n <= 10^{18}, 1 <= m <= 10^5 ) -- the size of bag and the number of boxes, respectively. The second line of each test case contains m integers a_1, a_2, ... , a_m ( 1 <= a_i <= 10^9 ) -- the sizes of boxes. It is guaranteed that each a_i is a power of two. It is also guaranteed that sum of all m over all test cases does not exceed 10^5 . For each test case print one integer -- the minimum number of divisions required to fill the bag of size n (or -1 , if it is impossible). '... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
70910508 |
chino123 |
D |
Feb. 12, 2020, 6:08 p.m. |
OK |
Clang++17 Diagnostics |
TESTS |
15 |
77 |
512000 |
|
1800 |
70889302 |
iica |
D |
Feb. 12, 2020, 3:59 p.m. |
OK |
D |
TESTS |
15 |
46 |
4300800 |
|
1800 |
70918830 |
rainboy |
D |
Feb. 12, 2020, 8:59 p.m. |
OK |
GNU C11 |
TESTS |
15 |
31 |
0 |
|
1800 |
70881183 |
StepMommy |
D |
Feb. 12, 2020, 3:38 p.m. |
OK |
GNU C11 |
TESTS |
15 |
31 |
409600 |
|
1800 |
70876226 |
pengin_2000 |
D |
Feb. 12, 2020, 3:26 p.m. |
OK |
GNU C11 |
TESTS |
15 |
31 |
819200 |
|
1800 |
70899687 |
clfzs |
D |
Feb. 12, 2020, 4:29 p.m. |
OK |
GNU C++11 |
TESTS |
15 |
15 |
0 |
|
1800 |
70956734 |
GOODer |
D |
Feb. 13, 2020, 1:01 p.m. |
OK |
GNU C++11 |
TESTS |
15 |
15 |
0 |
|
1800 |
70933610 |
Nice_to_meet_you |
D |
Feb. 13, 2020, 5:57 a.m. |
OK |
GNU C++11 |
TESTS |
15 |
15 |
409600 |
|
1800 |
70872293 |
WYXkk |
D |
Feb. 12, 2020, 3:17 p.m. |
OK |
GNU C++11 |
TESTS |
15 |
30 |
0 |
|
1800 |
70906949 |
Feng |
D |
Feb. 12, 2020, 5:20 p.m. |
OK |
GNU C++11 |
TESTS |
15 |
30 |
0 |
|
1800 |
70931509 |
luogu_bot4 |
D |
Feb. 13, 2020, 5:18 a.m. |
OK |
GNU C++11 |
TESTS |
15 |
30 |
0 |
|
1800 |
70950601 |
Flash_plus |
D |
Feb. 13, 2020, 11:12 a.m. |
OK |
GNU C++11 |
TESTS |
15 |
30 |
0 |
|
1800 |
70880860 |
LighTcml |
D |
Feb. 12, 2020, 3:37 p.m. |
OK |
GNU C++11 |
TESTS |
15 |
30 |
819200 |
|
1800 |
70923503 |
asjcx |
D |
Feb. 13, 2020, 12:39 a.m. |
OK |
GNU C++11 |
TESTS |
15 |
30 |
819200 |
|
1800 |
70883895 |
Sweetlemon |
D |
Feb. 12, 2020, 3:45 p.m. |
OK |
GNU C++11 |
TESTS |
15 |
30 |
1433600 |
|
1800 |
70956627 |
duock28cbg |
D |
Feb. 13, 2020, 12:59 p.m. |
OK |
GNU C++14 |
TESTS |
15 |
30 |
0 |
|
1800 |
70885521 |
marcOS |
D |
Feb. 12, 2020, 3:49 p.m. |
OK |
GNU C++14 |
TESTS |
15 |
30 |
0 |
|
1800 |
71066419 |
Chillstep |
D |
Feb. 14, 2020, 2:40 p.m. |
OK |
GNU C++14 |
TESTS |
15 |
30 |
409600 |
|
1800 |
70898035 |
nimishagarg_ng |
D |
Feb. 12, 2020, 4:25 p.m. |
OK |
GNU C++14 |
TESTS |
15 |
30 |
921600 |
|
1800 |
70957268 |
Icontofig |
D |
Feb. 13, 2020, 1:10 p.m. |
OK |
GNU C++14 |
TESTS |
15 |
31 |
0 |
|
1800 |
70945415 |
chick_magnet |
D |
Feb. 13, 2020, 9:36 a.m. |
OK |
GNU C++14 |
TESTS |
15 |
31 |
0 |
|
1800 |
70945244 |
chick_magnet |
D |
Feb. 13, 2020, 9:33 a.m. |
OK |
GNU C++14 |
TESTS |
15 |
31 |
0 |
|
1800 |
71044601 |
prakhar6381 |
D |
Feb. 14, 2020, 8:02 a.m. |
OK |
GNU C++14 |
TESTS |
15 |
31 |
0 |
|
1800 |
70992630 |
mohit2598 |
D |
Feb. 13, 2020, 3:48 p.m. |
OK |
GNU C++14 |
TESTS |
15 |
31 |
0 |
|
1800 |
71092362 |
chw0501 |
D |
Feb. 15, 2020, 2:40 a.m. |
OK |
GNU C++14 |
TESTS |
15 |
31 |
0 |
|
1800 |
70902360 |
Alphagocc |
D |
Feb. 12, 2020, 4:34 p.m. |
OK |
GNU C++17 |
TESTS |
15 |
15 |
921600 |
|
1800 |
70891563 |
Yami_Love_Yukee |
D |
Feb. 12, 2020, 4:06 p.m. |
OK |
GNU C++17 |
TESTS |
15 |
30 |
0 |
|
1800 |
70891365 |
seiko.iwasawa |
D |
Feb. 12, 2020, 4:05 p.m. |
OK |
GNU C++17 |
TESTS |
15 |
30 |
921600 |
|
1800 |
71047016 |
duzheting |
D |
Feb. 14, 2020, 8:45 a.m. |
OK |
GNU C++17 |
TESTS |
15 |
30 |
921600 |
|
1800 |
71049887 |
vjudge1 |
D |
Feb. 14, 2020, 9:36 a.m. |
OK |
GNU C++17 |
TESTS |
15 |
31 |
0 |
|
1800 |
71091707 |
vjudge3 |
D |
Feb. 15, 2020, 2:09 a.m. |
OK |
GNU C++17 |
TESTS |
15 |
31 |
0 |
|
1800 |
71073282 |
VietCT |
D |
Feb. 14, 2020, 4:33 p.m. |
OK |
GNU C++17 |
TESTS |
15 |
31 |
0 |
|
1800 |
71062043 |
Imagination01 |
D |
Feb. 14, 2020, 1:38 p.m. |
OK |
GNU C++17 |
TESTS |
15 |
31 |
0 |
|
1800 |
71061742 |
Maybach |
D |
Feb. 14, 2020, 1:34 p.m. |
OK |
GNU C++17 |
TESTS |
15 |
31 |
0 |
|
1800 |
71012475 |
192.168.1.1 |
D |
Feb. 13, 2020, 5:50 p.m. |
OK |
GNU C++17 |
TESTS |
15 |
31 |
0 |
|
1800 |
70903290 |
synapse |
D |
Feb. 12, 2020, 4:46 p.m. |
OK |
Go |
TESTS |
15 |
77 |
0 |
|
1800 |
70895382 |
synapse |
D |
Feb. 12, 2020, 4:17 p.m. |
OK |
Go |
TESTS |
15 |
93 |
0 |
|
1800 |
70883765 |
u1s1reallycai |
D |
Feb. 12, 2020, 3:44 p.m. |
OK |
Go |
TESTS |
15 |
109 |
0 |
|
1800 |
70933810 |
Azakarka |
D |
Feb. 13, 2020, 6:01 a.m. |
OK |
Java 11 |
TESTS |
15 |
186 |
0 |
|
1800 |
71088066 |
about |
D |
Feb. 14, 2020, 10:44 p.m. |
OK |
Java 11 |
TESTS |
15 |
187 |
0 |
|
1800 |
70940975 |
uwi |
D |
Feb. 13, 2020, 8:22 a.m. |
OK |
Java 11 |
TESTS |
15 |
187 |
0 |
|
1800 |
70928080 |
pikapika00 |
D |
Feb. 13, 2020, 3:41 a.m. |
OK |
Java 11 |
TESTS |
15 |
202 |
0 |
|
1800 |
70918065 |
lightseba |
D |
Feb. 12, 2020, 8:38 p.m. |
OK |
Java 11 |
TESTS |
15 |
202 |
0 |
|
1800 |
70914435 |
jenish9599 |
D |
Feb. 12, 2020, 7:18 p.m. |
OK |
Java 11 |
TESTS |
15 |
202 |
0 |
|
1800 |
70872940 |
ZeyadKhattab |
D |
Feb. 12, 2020, 3:18 p.m. |
OK |
Java 11 |
TESTS |
15 |
202 |
0 |
|
1800 |
70885501 |
adamjamil |
D |
Feb. 12, 2020, 3:49 p.m. |
OK |
Java 11 |
TESTS |
15 |
218 |
0 |
|
1800 |
71027956 |
elkadymohammed01 |
D |
Feb. 14, 2020, 1:26 a.m. |
OK |
Java 11 |
TESTS |
15 |
233 |
0 |
|
1800 |
71015219 |
AbdallahArafa |
D |
Feb. 13, 2020, 6:25 p.m. |
OK |
Java 11 |
TESTS |
15 |
233 |
2252800 |
|
1800 |
71024740 |
bluesky111 |
D |
Feb. 13, 2020, 10:33 p.m. |
OK |
Java 8 |
TESTS |
15 |
109 |
0 |
|
1800 |
71090761 |
MagentaCobra |
D |
Feb. 15, 2020, 1:22 a.m. |
OK |
Java 8 |
TESTS |
15 |
124 |
0 |
|
1800 |
71015863 |
thisSideAnonymous |
D |
Feb. 13, 2020, 6:35 p.m. |
OK |
Java 8 |
TESTS |
15 |
124 |
0 |
|
1800 |
70960328 |
Ad-007 |
D |
Feb. 13, 2020, 2:01 p.m. |
OK |
Java 8 |
TESTS |
15 |
124 |
0 |
|
1800 |
70936123 |
Katushechka |
D |
Feb. 13, 2020, 6:48 a.m. |
OK |
Java 8 |
TESTS |
15 |
124 |
0 |
|
1800 |
70926073 |
AnandOza |
D |
Feb. 13, 2020, 2:35 a.m. |
OK |
Java 8 |
TESTS |
15 |
124 |
0 |
|
1800 |
70924216 |
ijxjdjd |
D |
Feb. 13, 2020, 1:16 a.m. |
OK |
Java 8 |
TESTS |
15 |
124 |
0 |
|
1800 |
70912952 |
saurabhs1206 |
D |
Feb. 12, 2020, 6:50 p.m. |
OK |
Java 8 |
TESTS |
15 |
124 |
0 |
|
1800 |
70903951 |
petr_op |
D |
Feb. 12, 2020, 4:51 p.m. |
OK |
Java 8 |
TESTS |
15 |
124 |
0 |
|
1800 |
70897270 |
saurabhs1206 |
D |
Feb. 12, 2020, 4:23 p.m. |
OK |
Java 8 |
TESTS |
15 |
124 |
0 |
|
1800 |
70947462 |
Spheniscine |
D |
Feb. 13, 2020, 10:10 a.m. |
OK |
Kotlin |
TESTS |
15 |
124 |
0 |
|
1800 |
70947690 |
Spheniscine |
D |
Feb. 13, 2020, 10:14 a.m. |
OK |
Kotlin |
TESTS |
15 |
140 |
0 |
|
1800 |
70886338 |
yakamoto |
D |
Feb. 12, 2020, 3:51 p.m. |
OK |
Kotlin |
TESTS |
15 |
140 |
1024000 |
|
1800 |
remove filters
Back to search problems