119252024-11-19 19:22:40szabelrBenzinkút üzemeltetés (55)cpp17Accepted 55/552ms824 KiB
#include <iostream>
using namespace std;
int best[1000001]{ 0 },benzinkutak[1000001]{ 0 }, jok[1000001]{ 0 };
int main()
{
    int n, k,maxi=0;
    cin >> n >> k;
    int t[1001], h[1001];
    for (int i = 1; i <= n; i++) 
    {
        cin >> t[i] >> h[i];
        if (t[i] >= maxi)
            maxi = t[i];
        benzinkutak[t[i]] = i;
    }
    for (int i = 1; i <= maxi; i++)
    {
        best[i] = best[i - 1];
        if (benzinkutak[i] != 0) 
        {
            //best[i] = max(best[i], best[i - k] + h[benzinkutak[i]]);
            if (best[i] < best[i - k] + h[benzinkutak[i]]) {
                best[i] = best[i - k] + h[benzinkutak[i]];
                jok[i] = benzinkutak[i];
            }

        }
    }
    cout << best[maxi] << endl;
    int megoldas[1001], db = 0;
    int i = maxi;
    while (i > 0) {
        if (jok[i] == 0)
            i--;
        else {
            db++;
            megoldas[db] = jok[i];
            i = i - k;
        }   
    }
    cout << db << " ";
    for (int i = db; i >= 1; i--) {
        cout << megoldas[i] << " ";
    }
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/01ms500 KiB
2Accepted0/02ms824 KiB
3Accepted3/31ms320 KiB
4Accepted3/31ms320 KiB
5Accepted3/31ms320 KiB
6Accepted3/31ms500 KiB
7Accepted3/31ms320 KiB
8Accepted3/31ms320 KiB
9Accepted3/31ms320 KiB
10Accepted3/32ms320 KiB
11Accepted3/31ms320 KiB
12Accepted3/32ms568 KiB
13Accepted4/41ms320 KiB
14Accepted4/41ms568 KiB
15Accepted5/52ms756 KiB
16Accepted6/61ms320 KiB
17Accepted6/62ms824 KiB