57492023-09-16 11:43:56AblablablaBenzinkút üzemeltetés (55)cpp17Wrong answer 6/5532ms35240 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;

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

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

    ll a = 0;
    ll 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(ll i = 1; i <= n; i++){
        cin >> tavok[i] >> haszon[i];
    }

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

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

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

    cout << kutak.size() << " ";
    for(ll x : kutak){
        cout << x << " ";
    }
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base6/55
1Accepted0/03ms1688 KiB
2Wrong answer0/032ms33428 KiB
3Wrong answer0/33ms2132 KiB
4Wrong answer0/32ms2344 KiB
5Accepted3/33ms2484 KiB
6Wrong answer0/32ms2696 KiB
7Accepted3/32ms2764 KiB
8Wrong answer0/32ms2888 KiB
9Wrong answer0/33ms3268 KiB
10Wrong answer0/33ms3592 KiB
11Wrong answer0/33ms3804 KiB
12Wrong answer0/38ms10908 KiB
13Wrong answer0/410ms14672 KiB
14Wrong answer0/414ms19040 KiB
15Wrong answer0/518ms23872 KiB
16Wrong answer0/623ms28224 KiB
17Wrong answer0/632ms35240 KiB