3502021-10-25 16:58:00goczbaliBenzinkút üzemeltetés (55)cpp11Accepted 55/554ms3756 KiB
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long;

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/03ms1808 KiB
2Accepted0/04ms2516 KiB
3Accepted3/33ms2148 KiB
4Accepted3/33ms2380 KiB
5Accepted3/33ms2632 KiB
6Accepted3/33ms2560 KiB
7Accepted3/33ms2524 KiB
8Accepted3/33ms2660 KiB
9Accepted3/33ms2880 KiB
10Accepted3/33ms3112 KiB
11Accepted3/33ms3192 KiB
12Accepted3/33ms3256 KiB
13Accepted4/43ms3284 KiB
14Accepted4/43ms3276 KiB
15Accepted5/53ms3436 KiB
16Accepted6/64ms3460 KiB
17Accepted6/64ms3756 KiB