123382024-12-12 19:38:30Ablablabla1Benzinkút üzemeltetés (55)cpp17Wrong answer 36/5524ms4604 KiB
#include <bits/stdc++.h>

using namespace std;

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

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

    int 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(int i = 1; i <= n; i++){
        cin >> hely[i] >> ertek[i];
    }

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

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

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

    cout << ans.size() << " ";
    for(int x : ans) cout << x << " ";
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base36/55
1Accepted0/01ms320 KiB
2Accepted0/024ms4408 KiB
3Accepted3/31ms320 KiB
4Accepted3/31ms508 KiB
5Wrong answer0/31ms320 KiB
6Wrong answer0/31ms320 KiB
7Wrong answer0/31ms320 KiB
8Accepted3/31ms320 KiB
9Wrong answer0/31ms320 KiB
10Accepted3/31ms320 KiB
11Accepted3/31ms320 KiB
12Wrong answer0/36ms1492 KiB
13Accepted4/48ms1848 KiB
14Wrong answer0/410ms2488 KiB
15Accepted5/514ms3120 KiB
16Accepted6/617ms3732 KiB
17Accepted6/620ms4604 KiB