37512023-03-02 18:41:16hackemonBenzinkút üzemeltetés (55)cpp17Wrong answer 18/554ms3456 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];
    }
    if(pozicio.size() == 0) pozicio.push(pos+1);

    cout << pozicio.size() << ' ';
    for(int i = 0;i< n;i++)
    while(!pozicio.empty()) {
        cout << pozicio.top() << ' ';
        pozicio.pop();
    }
    cout << endl;
   return 0;
}
SubtaskSumTestVerdictTimeMemory
base18/55
1Accepted0/03ms1816 KiB
2Wrong answer0/04ms2064 KiB
3Wrong answer0/32ms2264 KiB
4Wrong answer0/33ms2480 KiB
5Accepted3/32ms2536 KiB
6Wrong answer0/33ms2788 KiB
7Accepted3/32ms2884 KiB
8Wrong answer0/33ms3016 KiB
9Wrong answer0/32ms3072 KiB
10Wrong answer0/32ms3080 KiB
11Wrong answer0/32ms3076 KiB
12Wrong answer0/33ms3092 KiB
13Wrong answer0/43ms3028 KiB
14Wrong answer0/43ms3160 KiB
15Wrong answer0/53ms3248 KiB
16Accepted6/64ms3376 KiB
17Accepted6/64ms3456 KiB