#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
extern pair<vector<int>, long long> transaction(long long M);
void buy_souvenirs(int N, long long P0) {
long long expless1 = P0 - 1;
if (N == 2) {
auto [gotten, change] = transaction(expless1);
return;
}
if(N == 3){
auto [gotten1, change1] = transaction(expless1);
ll use;
if(gotten1.size() == 1){
use = (expless1) - change1 - 1;
auto [gotten2, change2] = transaction(use);
auto [gotten3, change3] = transaction(use);
}
else{
use = (expless1 - change1 - 1) / 2;
auto [gotten2, change2] = transaction(use);
}
return;
}
vector<ll> prices(N);
vector<int> bought(N, 0);
prices[0] = P0;
long long diff = 2;
for (int i = 1; i < N; ++i) {
auto [gotten, change] = transaction(prices[i - 1] - 1);
for (auto item : gotten)
bought[item]++;
if (gotten.size() == 1) {
diff = 1 + change;
} else {
diff = max(diff, 2LL);
}
prices[i] = prices[i - 1] - diff;
diff = 2;
}
for (int i = 1; i < N; ++i) {
while (bought[i] < i) {
auto [gotten, change] = transaction(prices[i]);
for (int item : gotten)
bought[item]++;
}
}
}
# | 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... |