3522021-10-25 17:08:46goczbaliBenzinkút üzemeltetés (55)cpp14Accepted 55/554ms4080 KiB
#include <algorithm>
#include <iostream>
#include <vector>

#define ll long long

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;

    vector<ll> d(n + 1);
    vector<ll> c(n + 1);

    for (int i = 1; i <= n; i++) {
        cin >> d[i] >> c[i];
    }

    vector<ll> dp(n + 1);
    vector<vector<bool> > s(n + 1, vector<bool>(n + 1));

    for (int i = 1; i <= n; i++) {
        dp[i] = dp[i - 1];
        s[i] = s[i - 1];

        long j = distance(d.begin(), upper_bound(d.begin(), d.end(), d[i] - k)) - 1;
        if (j < 0) j = 0;

        if (c[i] + dp[j] > dp[i - 1]) {
            dp[i] = c[i] + dp[j];
            s[i] = s[j];
            s[i][i] = true;
        }
    }

    int count = 0;

    for (int i = 1; i <= n; i++) {
        if (s[n][i]) {
            count++;
        }
    }

    cout << dp[n] << endl;
    cout << count << " ";
    for (int i = 1; i <= n; i++) {
        if (s[n][i]) {
            cout << i << " ";
        }
    }
    cout << endl;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1816 KiB
2Accepted0/04ms2480 KiB
3Accepted3/33ms2236 KiB
4Accepted3/33ms2608 KiB
5Accepted3/33ms2620 KiB
6Accepted3/33ms2780 KiB
7Accepted3/33ms3012 KiB
8Accepted3/33ms3100 KiB
9Accepted3/33ms3192 KiB
10Accepted3/33ms3312 KiB
11Accepted3/33ms3280 KiB
12Accepted3/33ms3340 KiB
13Accepted4/43ms3364 KiB
14Accepted4/44ms3632 KiB
15Accepted5/54ms3896 KiB
16Accepted6/64ms4080 KiB
17Accepted6/64ms4028 KiB