Submission #1208641

#TimeUsernameProblemLanguageResultExecution timeMemory
1208641phungmanager0Happiness (Balkan15_HAPPINESS)C++20
0 / 100
0 ms320 KiB
#include "happiness.h" #include <bits/stdc++.h> using namespace std; multiset<long long> s[40]; long long sum[40]; void update(int x, bool del) { int k = 31 - __builtin_clz(x); if(del) { s[k].erase(x); sum[k] -= x; } else { s[k].insert(x); sum[k] += x; } } bool get() { long long tmp = 0; for(int i = 0; i < 40; i++) { if(s[i].size()) { auto it = s[i].begin(); if(*it <= tmp + 1) { if(s[i].size() > 1) { auto nextValue = next(it); if(tmp + *it + 1 < *nextValue) return 0; else tmp += sum[i]; } } else return false; } } return true; } bool is_happy(int event, int coinsCount, long long coins[]) { for(int i = 0; i < coinsCount; i++) { if(event == -1) update(coins[i], true); else update(coins[i], false); } return get(); } bool init(int coinsCount, long long maxCoinSize, long long coins[]) { for(int i = 0; i < coinsCount; i++) update(coins[i], false); return get(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...