This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
multiset<ll> group[40]; ll sum[40];
void upd(ll x, int op){ int g = log2(x);
if (op == -1) group[g].erase(group[g].find(x)), sum[g] -= x;
else group[g].insert(x), sum[g] += x;
}
bool solve(){
ll tot = 0;
for (int i = 0; i < 40; i++){
if (group[i].size() > 0) if (tot < *group[i].begin()-1) return 0;
if (group[i].size() > 1) if (tot+*group[i].begin() < *next(group[i].begin())-1) return 0;
tot += sum[i];
}return 1;
}
bool init(int n, ll mx, ll coins[]){
for (int i = 0; i < n; i++) upd(coins[i], 1);
return solve();
}
bool is_happy(int op, int n, ll coins[]){
for (int i = 0; i < n; i++) upd(coins[i], op);
return solve();
}
Compilation message (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |