Submission #1255968

#TimeUsernameProblemLanguageResultExecution timeMemory
1255968farhan11679축제 (IOI25_festival)C++20
Compilation error
0 ms0 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');
    }
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccYgRbB7.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccbboOyT.o:festival.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status