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 <set>
#define ll long long
#define X first
#define Y second
#define MP make_pair
using namespace std;
multiset<ll> st[42];
ll pr_sum[42];
void add(ll val, int tp){
int mx = 0; while((1ll << (mx + 1ll)) <= val) mx++;
if(tp == 1){
st[mx].insert(val), pr_sum[mx] += val;
}
else{
st[mx].erase(st[mx].find(val)), pr_sum[mx] -= val;
}
}
bool solve(){
ll sums = 0;
for(int i = 0;i < 41;i++){
if(st[i].empty())
continue;
ll x = *st[i].begin();
if(1 + sums < x)
return 0;
if(st[i].size() > 1 && 1 + sums + x < *next(st[i].begin()))
return 0;
sums += pr_sum[i];
}
return 1;
}
bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
for(int i = 0;i < coinsCount;i++)
add(coins[i], 1);
return solve();
}
bool is_happy(int event, int coinsCount, long long coins[]) {
for(int i = 0;i < coinsCount;i++)
add(coins[i], event);
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... |