3492021-10-25 16:57:04goczbaliBenzinkút üzemeltetés (55)cpp14Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base55/55
1Elfogadva0/03ms1816 KiB
2Elfogadva0/04ms2336 KiB
3Elfogadva3/33ms2172 KiB
4Elfogadva3/33ms2388 KiB
5Elfogadva3/33ms2528 KiB
6Elfogadva3/33ms2740 KiB
7Elfogadva3/33ms2976 KiB
8Elfogadva3/33ms3196 KiB
9Elfogadva3/33ms3288 KiB
10Elfogadva3/33ms3384 KiB
11Elfogadva3/33ms3468 KiB
12Elfogadva3/33ms3796 KiB
13Elfogadva4/43ms4024 KiB
14Elfogadva4/44ms4132 KiB
15Elfogadva5/54ms4184 KiB
16Elfogadva6/64ms4472 KiB
17Elfogadva6/64ms4760 KiB