70002023-12-26 10:48:08MagyarKendeSZLGBenzinkút üzemeltetés (55)cpp17Accepted 55/554ms4016 KiB
#include <iostream>
#include <vector>
#include <array>
#include <climits>
#include <algorithm>
#include <numeric>
#include <unordered_set>
#include <unordered_map>
#include <queue>

#define speed cin.tie(0); ios::sync_with_stdio(0)
#define range(start, exit, incr) for (int i = start; i exit; i incr)
#define cinv(v) for (auto& e : v) cin >> e;
#define all(v) v.begin(), v.end()

using namespace std;
using ll = long long;
using point = array<int, 2>;

int main() {
    speed;

    int N, K;
    cin >> N >> K;

    vector<int> T(N + 1), H(N + 1);
    vector<point> dp(N + 1);

    int maxi = 0;
    range(1, <= N, ++) {
        cin >> T[i] >> H[i];

        int j = 1, curr_best = 0;
        while (j < i && T[i] - T[j] >= K) {
            if (dp[curr_best][0] < dp[j][0]) {
                curr_best = j;
            }
            j++;
        }

        dp[i][0] = dp[curr_best][0] + H[i];
        dp[i][1] = curr_best;

        if (dp[maxi][0] < dp[i][0]) {
            maxi = i;
        }
    }

    cout << dp[maxi][0] << '\n';

    vector<int> path;
    while (maxi > 0) {
        path.push_back(maxi);
        maxi = dp[maxi][1];
    }

    cout << path.size();

    range(path.size() - 1, >= 0, --) {
        cout << ' ' << path[i];
    }
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms2008 KiB
2Accepted0/03ms2052 KiB
3Accepted3/33ms2240 KiB
4Accepted3/33ms2448 KiB
5Accepted3/33ms2664 KiB
6Accepted3/33ms2872 KiB
7Accepted3/33ms2960 KiB
8Accepted3/33ms3316 KiB
9Accepted3/33ms3452 KiB
10Accepted3/33ms3760 KiB
11Accepted3/33ms4016 KiB
12Accepted3/33ms3648 KiB
13Accepted4/43ms3608 KiB
14Accepted4/43ms3728 KiB
15Accepted5/53ms3748 KiB
16Accepted6/63ms3748 KiB
17Accepted6/64ms4008 KiB