#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pll pair<ll, ll>
#define pii pair<ll, pll>
#define pd pair<ld, ll>
#define pb push_back
#define fi first
#define se second
#include "happiness.h"
using namespace std;
const int N = 45;
const int M = 1300;
const ll mod = 1e15+7;
ll n, m, k, t, a[N], b[N], c[N], tong, ans, fe[N];
vector<ll> kq, adj[N];
vector<pll> P;
multiset<ll> st[N];
void add(ll x)
{
int i = 0;
while(1ll<<(i+1) <= x)++i;
st[i].insert(x);
fe[i] += x;
}
void del(ll x)
{
int i = 0;
while(1ll<<(i+1) <= x)++i;
st[i].erase(st[i].find(x));
fe[i] -= x;
}
bool ok()
{
ll total = 0;
for(int i = 0; i <= 40; i ++)
{
if(!st[i].empty())
{
if(total+1 < (*st[i].begin()))return false;
if(st[i].size() > 1 &&total+1+(*st[i].begin()) < (*next(st[i].begin())))return false;
}
total += fe[i];
}
return true;
}
bool init(int coinsCount, long long maxCoinSize, long long coins[]) {
for (int i = 0; i < coinsCount; ++i)add(coins[i]);
return ok();
}
bool is_happy(int event, int coinsCount, long long coins[]) {
for (int i = 0; i < coinsCount; ++i) {
if (event == -1) del(coins[i]);
else add(coins[i]);
}
return ok();
}
Compilation message
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 |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
6 ms |
860 KB |
Output is correct |
9 |
Correct |
6 ms |
844 KB |
Output is correct |
10 |
Correct |
5 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
202 ms |
5904 KB |
Output is correct |
7 |
Correct |
223 ms |
5916 KB |
Output is correct |
8 |
Correct |
185 ms |
5956 KB |
Output is correct |
9 |
Correct |
279 ms |
6064 KB |
Output is correct |
10 |
Correct |
460 ms |
8516 KB |
Output is correct |
11 |
Correct |
178 ms |
9924 KB |
Output is correct |
12 |
Correct |
188 ms |
9760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
6 ms |
860 KB |
Output is correct |
9 |
Correct |
6 ms |
844 KB |
Output is correct |
10 |
Correct |
5 ms |
844 KB |
Output is correct |
11 |
Correct |
202 ms |
5904 KB |
Output is correct |
12 |
Correct |
223 ms |
5916 KB |
Output is correct |
13 |
Correct |
185 ms |
5956 KB |
Output is correct |
14 |
Correct |
279 ms |
6064 KB |
Output is correct |
15 |
Correct |
460 ms |
8516 KB |
Output is correct |
16 |
Correct |
178 ms |
9924 KB |
Output is correct |
17 |
Correct |
188 ms |
9760 KB |
Output is correct |
18 |
Correct |
230 ms |
5880 KB |
Output is correct |
19 |
Correct |
246 ms |
5932 KB |
Output is correct |
20 |
Correct |
387 ms |
6340 KB |
Output is correct |
21 |
Correct |
240 ms |
6104 KB |
Output is correct |
22 |
Correct |
233 ms |
9788 KB |
Output is correct |
23 |
Correct |
221 ms |
9792 KB |
Output is correct |
24 |
Correct |
217 ms |
6056 KB |
Output is correct |