60012023-10-15 12:26:48CattBenzinkút üzemeltetés (55)cpp17Wrong answer 0/557ms11928 KiB
#include <iostream>
#include <vector>

using namespace std;

struct RestStop {
    int distance;
    int profit;
};

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

    vector<RestStop> restStops(N + 1);
    vector<vector<int>> dp(N + 1, vector<int>(N + 1, 0));

    for (int i = 1; i <= N; i++) {
        cin >> restStops[i].distance >> restStops[i].profit;
    }

    for (int i = 1; i <= N; i++) {
        for (int j = i - 1; j >= 0; j--) {
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);

            int distance = restStops[i].distance - restStops[j].distance;

            if (distance >= K) {
                dp[i][j] = max(dp[i][j], dp[j][j] + restStops[i].profit);
            }
        }
    }

    int maxProfit = 0;
    int lastStop = 0;
    for (int i = 1; i <= N; i++) {
        if (dp[N][i] > maxProfit) {
            maxProfit = dp[N][i];
            lastStop = i;
        }
    }

    cout << maxProfit << endl;

    vector<int> chosenStops;
    for (int i = lastStop; i >= 1; i--) {
        if (dp[lastStop][i] > dp[lastStop][i - 1]) {
            chosenStops.push_back(i);
            lastStop = i - 1;
        }
    }

    cout << chosenStops.size() << endl;
    for (int i = chosenStops.size() - 1; i >= 0; i--) {
        cout << chosenStops[i] << " ";
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/55
1Wrong answer0/03ms1944 KiB
2Wrong answer0/07ms10008 KiB
3Wrong answer0/33ms2296 KiB
4Wrong answer0/33ms2508 KiB
5Wrong answer0/33ms2732 KiB
6Wrong answer0/33ms2964 KiB
7Wrong answer0/33ms2908 KiB
8Wrong answer0/33ms3040 KiB
9Wrong answer0/33ms3172 KiB
10Wrong answer0/33ms3264 KiB
11Wrong answer0/33ms3564 KiB
12Wrong answer0/34ms5556 KiB
13Wrong answer0/44ms6528 KiB
14Wrong answer0/44ms7516 KiB
15Wrong answer0/56ms8764 KiB
16Wrong answer0/67ms10088 KiB
17Wrong answer0/67ms11928 KiB