#include "souvenirs.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef map<ll, ll> mp;
typedef pair<ll, ll> pll;
typedef queue<ll> qi;
typedef vector<ll> vi;
typedef vector <vi> vvi;
typedef vector <pll> vpl;
typedef vector <string> vs;
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define f first
#define s second
#define pb push_back
#define all(x) begin(x), end(x)
int g[105];
ll k[105];
int n;
ll p0;
void prep(ll ask) {
pair<vector<int>, long long> res = transaction(ask);
for(int i: res.f) {
g[i]++;
}
auto orz=res;
while(true) {
res=orz;
while(!res.f.empty() and k[res.f.back()]) {
res.s += k[res.f.back()];
res.f.pop_back();
}
if(res.f.size() == 1 and (res.f[0] == n-1 || k[res.f[0]+1])) {
k[res.f[0]] = ask - res.s;
break;
}
if(res.f.size() == 1) {
prep(ask-res.s-1);
}
else {
prep((ask - res.s) / (res.f.size()));
}
}
}
void buy_souvenirs(int N, long long P0) {
n = N;
p0 = P0;
k[0] = p0;
prep(p0-1);
for(int i = 0; i < n; i++) {
while(g[i] < i) {
transaction(k[i]);
g[i]++;
}
}
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |