57502023-09-16 12:26:20AblablablaBenzinkút üzemeltetés (55)cpp17Accepted 55/5529ms35140 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){
        //cout << akt << " " << elozo << "\n";
        if(dp[akt][elozo].second == 0){
            kutak.push_back(akt);
            elozo = akt;
            akt++;
        } else{
            akt++;
        }
    }

    cout << kutak.size() << " ";
    for(ll x : kutak){
        cout << x << " ";
    }
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms2084 KiB
2Accepted0/029ms33840 KiB
3Accepted3/32ms2448 KiB
4Accepted3/32ms2656 KiB
5Accepted3/33ms2872 KiB
6Accepted3/33ms3080 KiB
7Accepted3/32ms3168 KiB
8Accepted3/32ms3200 KiB
9Accepted3/33ms3552 KiB
10Accepted3/33ms3716 KiB
11Accepted3/33ms3964 KiB
12Accepted3/38ms11192 KiB
13Accepted4/410ms14788 KiB
14Accepted4/414ms18944 KiB
15Accepted5/518ms23884 KiB
16Accepted6/624ms28380 KiB
17Accepted6/629ms35140 KiB