30032023-02-08 07:59:27bzsofiaBenzinkút üzemeltetés (55)cpp11Accepted 55/553ms3824 KiB
#include <iostream>
#include <vector>
#include <deque>

using namespace std;

struct adat
{
    int elott, tav, sum;
    bool epit;
};

int n, i, j, mintav;
deque <int> v;

int main()
{
    cin>>n>>mintav;
    vector <adat> x(n+1);

    for (i=1; i<=n; ++i)
    {
        cin>>x[i].tav>>x[i].sum;

        j=i-1;
        while (j>=1 && x[i].tav-x[j].tav<mintav)
        {
            --j;
        }

        if (x[j].sum+x[i].sum>x[i-1].sum)
        {
            x[i].epit=1;
            x[i].sum+=x[j].sum;
            if (x[j].epit) x[i].elott=j;
            else x[i].elott=x[j].elott;

            if (i==n) v.push_back(n);
        }else
        {
            x[i].sum=x[i-1].sum;
            if (x[i-1].epit) x[i].elott=i-1;
            else x[i].elott=x[i-1].elott;
            x[i].tav=x[i-1].tav;
        }
    }

    cout<<x[n].sum<<"\n";

    i=n;
    while (x[i].elott!=0)
    {
        v.push_front(x[i].elott);
        i=x[i].elott;
    }

    cout<<v.size()<<" ";
    for (auto &e:v)
    {
        cout<<e<<" ";
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1808 KiB
2Accepted0/03ms2080 KiB
3Accepted3/33ms2272 KiB
4Accepted3/33ms2476 KiB
5Accepted3/32ms2452 KiB
6Accepted3/33ms2688 KiB
7Accepted3/33ms2896 KiB
8Accepted3/33ms2976 KiB
9Accepted3/33ms3064 KiB
10Accepted3/33ms3144 KiB
11Accepted3/33ms3276 KiB
12Accepted3/33ms3428 KiB
13Accepted4/43ms3604 KiB
14Accepted4/43ms3724 KiB
15Accepted5/53ms3744 KiB
16Accepted6/63ms3696 KiB
17Accepted6/63ms3824 KiB