Submission #442760

#TimeUsernameProblemLanguageResultExecution timeMemory
442760SirCovidThe19thHappiness (Balkan15_HAPPINESS)C++14
100 / 100
475 ms16068 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...