3492021-10-25 16:57:04goczbaliBenzinkút üzemeltetés (55)cpp14Accepted 55/554ms4760 KiB
#include <bits/stdc++.h>

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/03ms1816 KiB
2Accepted0/04ms2336 KiB
3Accepted3/33ms2172 KiB
4Accepted3/33ms2388 KiB
5Accepted3/33ms2528 KiB
6Accepted3/33ms2740 KiB
7Accepted3/33ms2976 KiB
8Accepted3/33ms3196 KiB
9Accepted3/33ms3288 KiB
10Accepted3/33ms3384 KiB
11Accepted3/33ms3468 KiB
12Accepted3/33ms3796 KiB
13Accepted4/43ms4024 KiB
14Accepted4/44ms4132 KiB
15Accepted5/54ms4184 KiB
16Accepted6/64ms4472 KiB
17Accepted6/64ms4760 KiB