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>
#define LL long long
const int log_mx=45;
std::multiset<LL> m[log_mx];
LL sum[log_mx];
void update(LL p, int event) {
int log_p=0;
while ((1LL<<(log_p+1)<=p)) log_p++;
if (event==1) {
m[log_p].insert(p);
sum[log_p]+=p;
}
else {
m[log_p].erase(m[log_p].find(p));
sum[log_p]-=p;
}
}
bool check() {
LL current=0;
for (int i=0; i<log_mx; i++) {
if (!m[i].empty()) {
LL x=*m[i].begin();
if (current+1<x) return false;
if (m[i].size()>1 and current+x+1<*next(begin(m[i]))) return false;
current+=sum[i];
}
}
return true;
}
bool init(int coinsCount, LL maxCoinSize, LL coins[]) {
for (int i=0; i<coinsCount; i++) {
update(coins[i], 1);
}
return check();
}
bool is_happy(int event, int coinsCount, LL coins[]) {
for (int i=0; i<coinsCount; i++) {
update(coins[i], event);
}
return check();
}
/*int main() {
std::ios_base::sync_with_stdio(0); std::cin.tie(0);
int n; LL m; std::cin>>n>>m;
LL coins[n];
for (int i=0; i<n; i++) std::cin>>coins[i];
std::cout<<init(n, m, coins)<<"\n";
int q; std::cin>>q;
while (q--) {
int e, k; std::cin>>e>>k;
LL coins[k];
for (int i=0; i<k; i++) std::cin>>coins[i];
std::cout<<is_happy(e, k, coins)<<"\n";
}
return 0;
}*/
Compilation message (stderr)
happiness.cpp:1:23: warning: extra tokens at end of #include directive
1 | #include "happiness.h";
| ^
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... |