7372022-01-03 14:55:34Szin AttilaBenzinkút üzemeltetés (55)cpp14Wrong answer 0/556ms3724 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;
    while(!ki.empty()) {
        cout << " " << ki.top();
        ki.pop();
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/55
1Wrong answer0/03ms1840 KiB
2Wrong answer0/04ms2204 KiB
3Wrong answer0/33ms2376 KiB
4Wrong answer0/33ms2456 KiB
5Wrong answer0/32ms2544 KiB
6Wrong answer0/33ms2672 KiB
7Wrong answer0/33ms2756 KiB
8Wrong answer0/32ms2752 KiB
9Wrong answer0/32ms2764 KiB
10Wrong answer0/32ms2840 KiB
11Wrong answer0/33ms2888 KiB
12Wrong answer0/33ms3104 KiB
13Wrong answer0/44ms3592 KiB
14Wrong answer0/44ms3544 KiB
15Wrong answer0/54ms3568 KiB
16Wrong answer0/64ms3576 KiB
17Wrong answer0/66ms3724 KiB