128702025-01-02 19:09:31BucsMateBenzinkút üzemeltetés (55)cpp17Accepted 55/553ms512 KiB
#include <iostream>
#include <stack>

using namespace std;

struct Piheno
{
    int tavolsag;
    int haszon;
};

Piheno pihenok[1001];

struct Dinamikus
{
    int haszon = 0;
    int elozo = 0;
};

Dinamikus dp[1001];

int main()
{
    int N, K;
    cin >> N >> K;
    for(int i = 1; i <= N; i++){
        cin >> pihenok[i].tavolsag >> pihenok[i].haszon;
    }
    for(int i = 1; i <= N; i++){
        int maxIndex = 0, maxHaszon = 0;
        for(int j = 0; j < i; j++){
            if(dp[j].haszon > maxHaszon && pihenok[i].tavolsag - pihenok[j].tavolsag >= K){
                maxHaszon = dp[j].haszon;
                maxIndex = j;
            }
        }
        dp[i].haszon = maxHaszon + pihenok[i].haszon;
        dp[i].elozo = maxIndex;
    }

    int megoldasHaszon = 0, megoldasIndex;
    for(int i = 1; i <= N; i++){
        if(megoldasHaszon < dp[i].haszon){
            megoldasHaszon = dp[i].haszon;
            megoldasIndex = i;
        }
    }
    int index = megoldasIndex;
    stack<int> st;

    while(index != 0){
        st.push(index);
        index = dp[index].elozo;
    }
    cout << megoldasHaszon << endl;
    cout << st.size() << " ";
    while(!st.empty()){
        cout << st.top() << " ";
        st.pop();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/01ms500 KiB
2Accepted0/03ms320 KiB
3Accepted3/31ms320 KiB
4Accepted3/31ms320 KiB
5Accepted3/31ms396 KiB
6Accepted3/31ms360 KiB
7Accepted3/31ms508 KiB
8Accepted3/31ms320 KiB
9Accepted3/31ms320 KiB
10Accepted3/31ms512 KiB
11Accepted3/31ms508 KiB
12Accepted3/31ms320 KiB
13Accepted4/42ms320 KiB
14Accepted4/42ms320 KiB
15Accepted5/52ms320 KiB
16Accepted6/62ms416 KiB
17Accepted6/62ms424 KiB