7473 2024. 01. 09 09:51:55 gkata Benzinkút üzemeltetés (55) cpp17 Elfogadva 55/55 3ms 4472 KiB
// benzinkut uzemeltetes.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>

using namespace std;

struct adat
{
    int tav, ljhaszon, elozo;
    bool volt;
};

vector<adat>x;
vector<int>m;

int n, k, i, h, j;
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> k;

    x.resize(n + 1);

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

        x[i].volt = true;
        x[i].ljhaszon = h;
        x[i].elozo = i;
        j = i - 1;

        while (j >= 1 && x[i].tav - x[j].tav < k)
        {
            if (x[j].ljhaszon>x[i].ljhaszon)
            {
                x[i].ljhaszon = x[j].ljhaszon;
                x[i].elozo = j;
                x[i].volt = false;
            }
            --j;
        }

        if (j)
        {
            if (x[j].ljhaszon + h > x[i].ljhaszon)
            {
                x[i].ljhaszon = x[j].ljhaszon + h;
                x[i].elozo = j;
                x[i].volt = true;
            }
        }

    }

    if (x[n].volt) m.push_back(n);
    i = n;

    while (x[i].elozo != i)
    {
        i = x[i].elozo;
        if (x[i].volt) m.push_back(i);
    }

    cout << x[n].ljhaszon << "\n" << m.size() << " ";
    for (i = m.size()-1; i >= 0; --i) cout << m[i] << " ";
}

/*
5 20
10 10
20 40
30 10
40 20
50 30
*/
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Részfeladat Összpont Teszt Verdikt Idő Memória
base 55/55
1 Elfogadva 0/0 3ms 1896 KiB
2 Elfogadva 0/0 3ms 2144 KiB
3 Elfogadva 3/3 3ms 2460 KiB
4 Elfogadva 3/3 3ms 2448 KiB
5 Elfogadva 3/3 3ms 2500 KiB
6 Elfogadva 3/3 3ms 2736 KiB
7 Elfogadva 3/3 3ms 3084 KiB
8 Elfogadva 3/3 3ms 3308 KiB
9 Elfogadva 3/3 3ms 3532 KiB
10 Elfogadva 3/3 3ms 3760 KiB
11 Elfogadva 3/3 3ms 3956 KiB
12 Elfogadva 3/3 3ms 4200 KiB
13 Elfogadva 4/4 3ms 4064 KiB
14 Elfogadva 4/4 3ms 4132 KiB
15 Elfogadva 5/5 3ms 4472 KiB
16 Elfogadva 6/6 3ms 4312 KiB
17 Elfogadva 6/6 3ms 4340 KiB