3512021-10-25 17:08:14goczbaliBenzinkút üzemeltetés (55)cpp14Elfogadva 55/554ms4228 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base55/55
1Elfogadva0/03ms1808 KiB
2Elfogadva0/04ms2520 KiB
3Elfogadva3/33ms2236 KiB
4Elfogadva3/33ms2444 KiB
5Elfogadva3/33ms2688 KiB
6Elfogadva3/33ms2740 KiB
7Elfogadva3/33ms2984 KiB
8Elfogadva3/33ms2980 KiB
9Elfogadva3/33ms3204 KiB
10Elfogadva3/33ms3404 KiB
11Elfogadva3/33ms3488 KiB
12Elfogadva3/33ms3800 KiB
13Elfogadva4/43ms4036 KiB
14Elfogadva4/43ms4004 KiB
15Elfogadva5/53ms4160 KiB
16Elfogadva6/64ms4192 KiB
17Elfogadva6/64ms4228 KiB