# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1255968 | farhan11679 | Festival (IOI25_festival) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
struct Coupon {
int idx;
long long price;
int type;
};
vector<int> max_coupons(int A, vector<int> P, vector<int> T) {
int N = P.size();
vector<int> result;
vector<bool> used(N, false);
// Min-heap for not-yet-affordable coupons by price
priority_queue<pair<long long,int>, vector<pair<long long,int>>, greater<>> not_affordable;
// Max-heap for affordable coupons by (type, -price)
priority_queue<tuple<int,long long,int>> affordable;
for (int i = 0; i < N; i++) {
not_affordable.push({P[i], i});
}
long long tokens = A;
while (true) {
// Move all affordable coupons into affordable heap
while (!not_affordable.empty() && not_affordable.top().first <= tokens) {
int idx = not_affordable.top().second;
not_affordable.pop();
affordable.push({T[idx], -P[idx], idx});
}
if (affordable.empty()) break;
// Pick best coupon
auto [t, negp, idx] = affordable.top();
affordable.pop();
if (used[idx]) continue; // skip duplicates
used[idx] = true;
// Buy it
tokens = (tokens - P[idx]) * T[idx];
result.push_back(idx);
}
return result;
}
// --- Sample grader usage ---
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
long long A;
cin >> N >> A;
vector<int> P(N), T(N);
for (int i = 0; i < N; i++) {
cin >> P[i] >> T[i];
}
auto res = max_coupons(A, P, T);
cout << res.size() << "\n";
for (int i = 0; i < (int)res.size(); i++) {
cout << res[i] << (i + 1 < (int)res.size() ? ' ' : '\n');
}
}