123432024-12-12 20:13:00AblablablaBenzinkút üzemeltetés (55)cpp17Wrong answer 36/5526ms8512 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll n, k;
vector<ll> hely, ertek;
vector<vector<ll>> dp;
vector<vector<bool>> irany;

ll megold(ll ind, ll elozo){
    if(ind == n + 1){
        return 0;
    }
    if(dp[ind][elozo] != -1){
        return dp[ind][elozo];
    }

    ll a = megold(ind + 1, elozo), b = 0;
    if(hely[elozo] + k <= hely[ind]){
        b = megold(ind + 1, ind) + ertek[ind];
    }

    if(a <= b){
        irany[ind][elozo] = 1;
    }

    return dp[ind][elozo] = max(a, b);
}

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

    hely.assign(n + 1, 0);
    ertek.assign(n + 1, 0);
    hely[0] = -1e9;
    for(ll i = 1; i <= n; i++){
        cin >> hely[i] >> ertek[i];
    }

    dp.assign(n + 1, vector<ll>(n + 1, -1));
    irany.assign(n + 1, vector<bool>(n + 1, 0));

    cout << megold(1, 0) << "\n";

    vector<ll> ans;
    ll egy = 1, ket = 0;
    while(egy <= n && ket <= n){
        if(ket >= egy){
            cout << egy << " " << ket << "\n";
        }
        assert(ket < egy);
        if(irany[egy][ket]){
            ans.push_back(egy);
            ket = egy;
            egy++;
        } else{
            egy++;
        }
    }

    cout << ans.size() << " ";
    for(ll x : ans) cout << x << " ";
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base36/55
1Accepted0/01ms320 KiB
2Accepted0/026ms8504 KiB
3Accepted3/31ms320 KiB
4Accepted3/31ms320 KiB
5Wrong answer0/31ms320 KiB
6Wrong answer0/31ms320 KiB
7Wrong answer0/31ms320 KiB
8Accepted3/31ms320 KiB
9Wrong answer0/31ms552 KiB
10Accepted3/31ms320 KiB
11Accepted3/31ms568 KiB
12Wrong answer0/36ms2284 KiB
13Accepted4/48ms3140 KiB
14Wrong answer0/413ms4152 KiB
15Accepted5/514ms5620 KiB
16Accepted6/619ms6808 KiB
17Accepted6/621ms8512 KiB