7382022-01-03 14:56:30Szin AttilaBenzinkút üzemeltetés (55)cpp14Accepted 55/556ms4024 KiB
#include <bits/stdc++.h>
using namespace std;
const int c = 2 * 1e3;
typedef long long ll;

int dp[c], p[c];
pair<int, int> v[c];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n,k;
    cin >> n >> k;

    for(int i = 0; i < n; i++) {
        cin >> v[i].first >> v[i].second;
    }

    for(int i = 0; i < n; i++) {
        dp[i] = v[i].second;
        p[i] = i;
        for(int j = 0; j < i && v[j].first + k <= v[i].first; j++) {
            if(dp[i] < dp[j] + v[i].second) {
                dp[i] = dp[j] + v[i].second;
                p[i] = j;
            }
        }
    }
    int mo, maxi = 0;
    for(int i = 0; i < n; i++) {
        if(dp[i] > maxi) {
            maxi = dp[i];
            mo = i;
        }
    }

    stack<int> ki;
    int curr = mo;
    while(curr != p[curr]) {
        ki.push(curr+1);
        curr = p[curr];
    }
    cout << maxi << "\n" << ki.size() + 1 << " " << curr+1;
    while(!ki.empty()) {
        cout << " " << ki.top();
        ki.pop();
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1836 KiB
2Accepted0/06ms2208 KiB
3Accepted3/33ms2532 KiB
4Accepted3/33ms2524 KiB
5Accepted3/33ms2736 KiB
6Accepted3/33ms2820 KiB
7Accepted3/33ms2924 KiB
8Accepted3/32ms3012 KiB
9Accepted3/33ms3140 KiB
10Accepted3/33ms3224 KiB
11Accepted3/33ms3496 KiB
12Accepted3/33ms3456 KiB
13Accepted4/44ms3472 KiB
14Accepted4/44ms3800 KiB
15Accepted5/54ms3880 KiB
16Accepted6/64ms4024 KiB
17Accepted6/66ms4012 KiB