36462023-03-01 16:58:06nkdorka1212Benzinkút üzemeltetés (55)cpp17Accepted 55/554ms3872 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    vector<pair<int,int>>kutak(n+1,{0,0});  //tav , haszon
    vector<int>dp(n+1,0);
    vector<int>szulo(n+1,0);
    for(int i=1;i<=n;i++)
    {
        cin>>kutak[i].first>>kutak[i].second;
    }
    dp[1]=kutak[1].second;
    for(int i=2;i<=n;i++)
    {
        dp[i]=kutak[i].second;
        for(int j=i-1;j>=1;j--)
        {
            if(kutak[i].first-kutak[j].first>=k)
            {
                if(dp[j]+kutak[i].second > dp[i])
                {
                    dp[i]=dp[j]+kutak[i].second;
                    szulo[i]=j;
                }
            }
        }
    }
    int utso=1;
    for(int i=2;i<=n;i++)
    {
        if(dp[i]>dp[utso])
        {
            utso=i;
        }
    }
    cout<<dp[utso]<<"\n";
    stack<int>mo;
    mo.push(utso);
    while(szulo[utso]!=0)
    {
        mo.push(szulo[utso]);
        utso=szulo[utso];
    }
    cout<<mo.size()<<" ";
    while(!mo.empty())
    {
        cout<<mo.top()<<" ";
        mo.pop();
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1808 KiB
2Accepted0/04ms2016 KiB
3Accepted3/33ms2240 KiB
4Accepted3/33ms2428 KiB
5Accepted3/32ms2508 KiB
6Accepted3/33ms2760 KiB
7Accepted3/33ms2992 KiB
8Accepted3/33ms3044 KiB
9Accepted3/33ms3184 KiB
10Accepted3/33ms3300 KiB
11Accepted3/33ms3420 KiB
12Accepted3/33ms3520 KiB
13Accepted4/43ms3752 KiB
14Accepted4/43ms3872 KiB
15Accepted5/54ms3716 KiB
16Accepted6/64ms3684 KiB
17Accepted6/64ms3684 KiB