37452023-03-02 18:26:53hackemonBenzinkút üzemeltetés (55)cpp17Wrong answer 18/554ms3772 KiB
#include <bits/stdc++.h>
using namespace std;


int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n), d(n); // value and distance
    vector<int> dp(n), pr(n); // dp and previous element 

    for(int i = 0 ;i< n;i++ ) {
        cin >> d[i] >> v[i];
        dp[i] = v[i];
    }
    for(int i = 0;i< n;i++ ) {
        for(int j = 0;j< i;j++ ) {
            if(dp[i] < dp[j] + v[i] && d[i] - d[j] >= k) {
                dp[i] = dp[j] + v[i];
                pr[i] = j;
            }
        }
    }
    
    int ma = 0;
    int pos = 0;
    for(int i = 0;i< n;i++ ) {
        if(dp[i] > ma) {
            ma = dp[i];
            pos = i;
        }
    }
    cout << ma << endl;

    stack<int> pozicio;
    while(pr[pos] != pos) {
        pozicio.push(pos+1);
        pos = pr[pos];
    }
    cout << pozicio.size() << ' ';
    
    while(!pozicio.empty()) {
        cout << pozicio.top() << ' ';
        pozicio.pop();
    }
    cout << endl;
   return 0;
}
SubtaskSumTestVerdictTimeMemory
base18/55
1Accepted0/03ms1812 KiB
2Wrong answer0/04ms2348 KiB
3Wrong answer0/33ms2496 KiB
4Wrong answer0/32ms2580 KiB
5Accepted3/33ms2704 KiB
6Wrong answer0/32ms2720 KiB
7Accepted3/33ms2952 KiB
8Wrong answer0/32ms3036 KiB
9Wrong answer0/33ms3164 KiB
10Wrong answer0/32ms3220 KiB
11Wrong answer0/33ms3492 KiB
12Wrong answer0/33ms3532 KiB
13Wrong answer0/43ms3664 KiB
14Wrong answer0/43ms3772 KiB
15Wrong answer0/53ms3756 KiB
16Accepted6/64ms3764 KiB
17Accepted6/64ms3756 KiB