57482023-09-16 11:42:55AblablablaBenzinkút üzemeltetés (55)cpp17Wrong answer 6/5528ms19440 KiB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

int n, k;
vector<int> tavok;
vector<int> haszon;
vector<vector<pii>> dp;

int megold(int akt, int elozo){
    if(akt == n + 1){
        return 0;
    } else if(dp[akt][elozo] != (pii){-1, -1}){
        return dp[akt][elozo].first;
    }

    int a = 0;
    int b = megold(akt + 1, elozo);

    if(tavok[akt] - tavok[elozo] >= k){
        a = megold(akt + 1, akt) + haszon[akt];
    }

    if(a > b){
        dp[akt][elozo] = {a, 0};
    } else{
        dp[akt][elozo] = {b, 1};
    }

    return dp[akt][elozo].first;
}



int main()
{
    cin >> n >> k;

    tavok.assign(n + 1, 0);
    haszon.assign(n + 1, 0);
    tavok[0] = 0 - k - 1;
    haszon[0] = 0 - k - 1;

    for(int i = 1; i <= n; i++){
        cin >> tavok[i] >> haszon[i];
    }

    dp.assign(n + 1, vector<pii>(n + 1, {-1, -1}));
    int maxi = megold(1, 0);
    cout << maxi << "\n";

    int akt = 1;
    int elozo = 0;
    vector<int> kutak;

    while(akt <= n){
        if(dp[akt][elozo].second == 0){
            kutak.push_back(akt);
            akt++;
            elozo = akt;
        } else{
            akt++;
        }
    }

    cout << kutak.size() << " ";
    for(int x : kutak){
        cout << x << " ";
    }
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base6/55
1Accepted0/03ms1812 KiB
2Wrong answer0/028ms17616 KiB
3Wrong answer0/33ms2192 KiB
4Wrong answer0/32ms2288 KiB
5Accepted3/32ms2520 KiB
6Wrong answer0/33ms2616 KiB
7Accepted3/33ms2728 KiB
8Wrong answer0/33ms2840 KiB
9Wrong answer0/33ms3408 KiB
10Wrong answer0/33ms3424 KiB
11Wrong answer0/33ms3836 KiB
12Wrong answer0/38ms7664 KiB
13Wrong answer0/410ms9336 KiB
14Wrong answer0/414ms11412 KiB
15Wrong answer0/519ms13676 KiB
16Wrong answer0/623ms16280 KiB
17Wrong answer0/627ms19440 KiB