173002025-06-20 15:48:56MrkzBenzinkút üzemeltetés (55)cpp17Accepted 55/552ms508 KiB
#include <bits/stdc++.h>

using namespace std;

struct Benzinkut {
    int tav;
    int hozam;
};

int main() {
    int N, K;
    cin >> N >> K;

    vector<Benzinkut> B(N);
    for (int i = 0; i < N; i++) {
        cin >> B[i].tav >> B[i].hozam;
    }


    vector<int> dp(N, 0);

    vector<int> prev(N, -1);


    dp[0] = B[0].hozam;
    for (int i = 1; i < N; i++) {
        dp[i] = B[i].hozam;
        for (int j = 0; j < i; j++) {

            if (B[i].tav - B[j].tav >= K) {
                if (dp[j] + B[i].hozam > dp[i]) {
                    dp[i] = dp[j] + B[i].hozam;
                    prev[i] = j;
                }
            }
        }
    }


    int maxProfit = *max_element(dp.begin(), dp.end());
    int maxIndex = max_element(dp.begin(), dp.end()) - dp.begin();


    vector<int> megoldas;
    while (maxIndex != -1) {
        megoldas.push_back(maxIndex + 1);
        maxIndex = prev[maxIndex];
    }


    reverse(megoldas.begin(), megoldas.end());


    cout << maxProfit << endl;
    cout << megoldas.size() << " ";
    for (int index : megoldas) {
        cout << index << " ";
    }
    cout << endl;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/01ms316 KiB
2Accepted0/02ms316 KiB
3Accepted3/31ms508 KiB
4Accepted3/31ms316 KiB
5Accepted3/31ms316 KiB
6Accepted3/31ms316 KiB
7Accepted3/31ms316 KiB
8Accepted3/31ms316 KiB
9Accepted3/31ms316 KiB
10Accepted3/31ms316 KiB
11Accepted3/31ms316 KiB
12Accepted3/32ms316 KiB
13Accepted4/42ms316 KiB
14Accepted4/42ms412 KiB
15Accepted5/52ms420 KiB
16Accepted6/62ms316 KiB
17Accepted6/62ms316 KiB