#include "happiness.h"
#include <bits/stdc++.h>
const int MAX = 45 ;
using namespace std ;
map<long long , int > del ;
long long s[MAX] ;
priority_queue< long long, vector<long long> , greater<long long> > fila[MAX] ;
bool is_happy(int event, int coinsCount, long long coins[]) {
for(int i = 0 ; i < coinsCount ; i++ ){
int bit = 64-__builtin_clzll(coins[i]) ;
if(event == 1){
s[bit] += coins[i] ;
fila[bit].push(coins[i]) ;
}
else{
s[bit] -= coins[i] ;
del[coins[i]]++ ;
}
}
long long ss = 0 ;
for(int i = 0 ; i <= 40 ; i++ ){
while( !fila[i].empty() && del[ fila[i].top() ] ){
del[ fila[i].top() ]-- ;
fila[i].pop() ;
}
if( !fila[i].empty() && fila[i].top() > ss+1 ) return false ;
ss += s[i] ;
}
return true ;
}
bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
return is_happy( 1 , coinsCount, coins ) ;
}
Compilation message
grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
16 | long long max_code;
| ^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
5 ms |
956 KB |
Output is correct |
9 |
Correct |
5 ms |
844 KB |
Output is correct |
10 |
Correct |
4 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
236 ms |
17064 KB |
Output is correct |
7 |
Correct |
232 ms |
16700 KB |
Output is correct |
8 |
Correct |
257 ms |
17064 KB |
Output is correct |
9 |
Correct |
334 ms |
23876 KB |
Output is correct |
10 |
Correct |
288 ms |
21904 KB |
Output is correct |
11 |
Correct |
109 ms |
16824 KB |
Output is correct |
12 |
Correct |
126 ms |
16392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
308 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
5 ms |
956 KB |
Output is correct |
9 |
Correct |
5 ms |
844 KB |
Output is correct |
10 |
Correct |
4 ms |
716 KB |
Output is correct |
11 |
Correct |
236 ms |
17064 KB |
Output is correct |
12 |
Correct |
232 ms |
16700 KB |
Output is correct |
13 |
Correct |
257 ms |
17064 KB |
Output is correct |
14 |
Correct |
334 ms |
23876 KB |
Output is correct |
15 |
Correct |
288 ms |
21904 KB |
Output is correct |
16 |
Correct |
109 ms |
16824 KB |
Output is correct |
17 |
Correct |
126 ms |
16392 KB |
Output is correct |
18 |
Correct |
320 ms |
20708 KB |
Output is correct |
19 |
Correct |
287 ms |
20300 KB |
Output is correct |
20 |
Correct |
371 ms |
27716 KB |
Output is correct |
21 |
Correct |
267 ms |
18380 KB |
Output is correct |
22 |
Correct |
118 ms |
18344 KB |
Output is correct |
23 |
Correct |
139 ms |
18872 KB |
Output is correct |
24 |
Correct |
312 ms |
20556 KB |
Output is correct |