17892022-12-03 15:32:29kovacs.peter.18fBenzinkút üzemeltetés (55)cpp11Wrong answer 46/5514ms27276 KiB
#include <iostream>
#include <vector>
#include <stack>

using namespace std;

struct point {
    int benefit = 0, distance = 0, last_index = 0;
};

int main() {
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    int N, K, T, H;
    cin >> N >> K;
    vector<point> dpS(1000001);
    for (int i = 0, index = 1; i < N; i++) {
        cin >> T >> H;
        while (index <= T) {
            dpS[index] = dpS[index - 1];
            ++index;
        }
        if (T >= K && dpS[T - K].benefit + H > dpS[T].benefit) {
            dpS[T].benefit = dpS[T - K].benefit + H;
            dpS[T].distance = T;
            dpS[T].last_index = i;
        }
        else if (H > dpS[T].benefit) {
            dpS[T].benefit = H;
            dpS[T].distance = T;
            dpS[T].last_index = i;
        }
    }
    stack<point> answerS;
    answerS.push(dpS[T]);
    while (answerS.top().distance > K) {
        answerS.push(dpS[answerS.top().distance - K]);
    }
    cout << dpS[T].benefit << '\n' << answerS.size() << " ";
    while (!answerS.empty()) {
        cout << answerS.top().last_index + 1 << " ";
        answerS.pop();
    }
    cout << '\n';
}
SubtaskSumTestVerdictTimeMemory
base46/55
1Accepted0/010ms25260 KiB
2Accepted0/010ms25464 KiB
3Accepted3/313ms25676 KiB
4Accepted3/310ms25932 KiB
5Wrong answer0/310ms26172 KiB
6Accepted3/310ms26352 KiB
7Accepted3/313ms26524 KiB
8Accepted3/310ms26660 KiB
9Accepted3/310ms26612 KiB
10Accepted3/310ms26608 KiB
11Accepted3/310ms26608 KiB
12Accepted3/310ms26608 KiB
13Accepted4/410ms26740 KiB
14Accepted4/410ms26820 KiB
15Accepted5/510ms26932 KiB
16Wrong answer0/610ms27068 KiB
17Accepted6/614ms27276 KiB