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 "happiness.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
multiset<ll> todo[40];
ll SUM[40];
void ad(ll x, int b) {
int p = 0; while ((1LL<<(p+1)) <= x) p ++;
if (b == 1) {
todo[p].insert(x), SUM[p] += x;
} else {
todo[p].erase(todo[p].find(x)), SUM[p] -= x;
}
}
bool ok() {
ll sum = 0;
for (int i = 0; i < 40; ++i) if (todo[i].size() > 0) {
ll x = *begin(todo[i]);
if (sum+1 < x) return 0;
if (todo[i].size() > 1 && sum+x+1 < *next(begin(todo[i]))) return 0;
sum += SUM[i];
}
return 1;
}
bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
for (int i = 0; i < coinsCount; ++i) ad(coins[i],1);
return ok();
}
bool is_happy(int event, int coinsCount, long long coins[]) {
for (int i = 0; i < coinsCount; ++i) {
if (event == -1) ad(coins[i],-1);
else ad(coins[i],1);
}
return ok();
}
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... |