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"Polycarp has n coins, the value of the i -th coin is a_i . It is guaranteed that all the values are integer powers of 2 (i.e. a_i = 2^d for some non-negative integer number d ). Polycarp wants to know answers on q queries. The j -th query is described as integer number b_j . The answer to the query is the minimum number of coins that is necessary to obtain the value b_j using some subset of coins (Polycarp can use only coins he has). If Polycarp can't obtain the value b_j , the answer to the j -th query is -1. The queries are independent (the answer on the query doesn't affect Polycarp's coins). The first line of the input contains two integers n and q ( 1 <= n, q <= 2 cdot 10^5 ) -- the number of coins and the number of queries. The second line of the input contains n integers a_1, a_2, ... , a_n -- values of coins ( 1 <= a_i <= 2 cdot 10^9 ). It is guaranteed that all a_i are integer powers of 2 (i.e. a_i = 2^d for some non-negative integer number d ). The next q lines contain one integer each. The j -th line contains one integer b_j -- the value of the j -th query ( 1 <= b_j <= 10^9 ). Print q integers ans_j . The j -th integer must be equal to the answer on the j -th query. If Polycarp can't obtain the value b_j the answer to the j -th query is -1. "... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
39920689 |
petr577 |
D |
July 3, 2018, 4:03 p.m. |
OK |
FPC |
TESTS |
31 |
499 |
0 |
|
1600 |
39922953 |
Ulanov_Victor |
D |
July 3, 2018, 4:14 p.m. |
OK |
FPC |
TESTS |
31 |
514 |
819200 |
|
1600 |
39918768 |
1353055672 |
D |
July 3, 2018, 3:55 p.m. |
OK |
FPC |
TESTS |
31 |
529 |
0 |
|
1600 |
39922561 |
Potassium |
D |
July 3, 2018, 4:12 p.m. |
OK |
FPC |
TESTS |
31 |
717 |
0 |
|
1600 |
39912767 |
ndhuy |
D |
July 3, 2018, 3:30 p.m. |
OK |
FPC |
TESTS |
31 |
1325 |
0 |
|
1600 |
39907260 |
CCF_NOI |
D |
July 3, 2018, 3:11 p.m. |
OK |
GNU C |
TESTS |
31 |
171 |
0 |
|
1600 |
39914704 |
aniket.shrimal |
D |
July 3, 2018, 3:38 p.m. |
OK |
GNU C |
TESTS |
31 |
234 |
0 |
|
1600 |
39919348 |
Pigbrain |
D |
July 3, 2018, 3:57 p.m. |
OK |
GNU C++ |
TESTS |
31 |
93 |
0 |
|
1600 |
39916759 |
elijahqi |
D |
July 3, 2018, 3:46 p.m. |
OK |
GNU C++ |
TESTS |
31 |
124 |
1126400 |
|
1600 |
39924558 |
Dfkdsmbd |
D |
July 3, 2018, 4:21 p.m. |
OK |
GNU C++ |
TESTS |
31 |
124 |
1638400 |
|
1600 |
39920592 |
dyume |
D |
July 3, 2018, 4:03 p.m. |
OK |
GNU C++ |
TESTS |
31 |
139 |
0 |
|
1600 |
39921645 |
G___j_ |
D |
July 3, 2018, 4:08 p.m. |
OK |
GNU C++ |
TESTS |
31 |
140 |
307200 |
|
1600 |
39921781 |
jiang2003 |
D |
July 3, 2018, 4:08 p.m. |
OK |
GNU C++ |
TESTS |
31 |
155 |
307200 |
|
1600 |
39921358 |
JZYshuraK |
D |
July 3, 2018, 4:06 p.m. |
OK |
GNU C++ |
TESTS |
31 |
155 |
409600 |
|
1600 |
39907088 |
cavary_cl |
D |
July 3, 2018, 3:10 p.m. |
OK |
GNU C++ |
TESTS |
31 |
155 |
2457600 |
|
1600 |
39912372 |
shanxizeng |
D |
July 3, 2018, 3:29 p.m. |
OK |
GNU C++ |
TESTS |
31 |
156 |
0 |
|
1600 |
39926733 |
HighFleet |
D |
July 3, 2018, 4:31 p.m. |
OK |
GNU C++ |
TESTS |
31 |
171 |
0 |
|
1600 |
39907138 |
serener |
D |
July 3, 2018, 3:10 p.m. |
OK |
GNU C++11 |
TESTS |
31 |
93 |
16896000 |
|
1600 |
39907569 |
lzqaq |
D |
July 3, 2018, 3:12 p.m. |
OK |
GNU C++11 |
TESTS |
31 |
124 |
0 |
|
1600 |
39919056 |
Mappy007 |
D |
July 3, 2018, 3:56 p.m. |
OK |
GNU C++11 |
TESTS |
31 |
124 |
307200 |
|
1600 |
39917483 |
YangDavid |
D |
July 3, 2018, 3:49 p.m. |
OK |
GNU C++11 |
TESTS |
31 |
124 |
307200 |
|
1600 |
39913985 |
Naruse_Shiroha |
D |
July 3, 2018, 3:35 p.m. |
OK |
GNU C++11 |
TESTS |
31 |
124 |
2457600 |
|
1600 |
39905463 |
PrinzEugen |
D |
July 3, 2018, 3:04 p.m. |
OK |
GNU C++11 |
TESTS |
31 |
139 |
0 |
|
1600 |
39911402 |
Bunnycxk |
D |
July 3, 2018, 3:25 p.m. |
OK |
GNU C++11 |
TESTS |
31 |
155 |
307200 |
|
1600 |
39923662 |
Code_Cancer |
D |
July 3, 2018, 4:17 p.m. |
OK |
GNU C++11 |
TESTS |
31 |
156 |
307200 |
|
1600 |
39912388 |
Bezout |
D |
July 3, 2018, 3:29 p.m. |
OK |
GNU C++11 |
TESTS |
31 |
156 |
409600 |
|
1600 |
39916795 |
tienthanh214 |
D |
July 3, 2018, 3:46 p.m. |
OK |
GNU C++11 |
TESTS |
31 |
156 |
1126400 |
|
1600 |
39919361 |
1500nmlss |
D |
July 3, 2018, 3:57 p.m. |
OK |
GNU C++14 |
TESTS |
31 |
171 |
0 |
|
1600 |
39911356 |
cprayer |
D |
July 3, 2018, 3:25 p.m. |
OK |
GNU C++14 |
TESTS |
31 |
171 |
307200 |
|
1600 |
39916884 |
ianahao |
D |
July 3, 2018, 3:47 p.m. |
OK |
GNU C++14 |
TESTS |
31 |
171 |
1126400 |
|
1600 |
39924024 |
brekaish |
D |
July 3, 2018, 4:18 p.m. |
OK |
GNU C++14 |
TESTS |
31 |
171 |
1638400 |
|
1600 |
39921708 |
Moamen. |
D |
July 3, 2018, 4:08 p.m. |
OK |
GNU C++14 |
TESTS |
31 |
171 |
2457600 |
|
1600 |
39925329 |
Molo5ya |
D |
July 3, 2018, 4:24 p.m. |
OK |
GNU C++14 |
TESTS |
31 |
186 |
204800 |
|
1600 |
39923718 |
farhanshahoriar |
D |
July 3, 2018, 4:17 p.m. |
OK |
GNU C++14 |
TESTS |
31 |
187 |
0 |
|
1600 |
39920199 |
Rogue33 |
D |
July 3, 2018, 4:01 p.m. |
OK |
GNU C++14 |
TESTS |
31 |
187 |
0 |
|
1600 |
39917090 |
Luka |
D |
July 3, 2018, 3:48 p.m. |
OK |
GNU C++14 |
TESTS |
31 |
187 |
0 |
|
1600 |
39911689 |
minty99 |
D |
July 3, 2018, 3:26 p.m. |
OK |
GNU C++14 |
TESTS |
31 |
187 |
0 |
|
1600 |
remove filters
Back to search problems