# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1260342 | robijoy | 선물 (IOI25_souvenirs) | C++20 | 0 ms | 0 KiB |
/*
* Starting with the name of almighty ALLAH
*/
#include "souvenirs.h"
// #include <bits/stdc++.h>
using namespace std;
#define int long long
void buy_souvenirs(int N, long long P0) {
vector<int> left(N);
for (int i = 0; i < N; ++i) left[i] = i;
int LowerPN = max(1LL,P0 - (2*N)); // the least limit of the last sou..
int PN = -1;
for (int i = LowerPN; i < P0; ++i)
{
pair<vector<int>, long long> res = transaction(i);
if(res.first.size() == 1) {
PN = i;
left[PN] --;
break;
}
}
// we got P0 and the last price too.
for (int i = PN+1; i < P0; ++i)
{
pair<vector<int>, long long> res = transaction(i);
vector<int> robi = res.first;
for(auto it:robi) left[it]--;
}
for (int i = 0; i < N; ++i)
{
int cur = i;
for(int j = 0; j < left[i]; j++) {
transaction(cur);
}
}
}