240822026-02-04 07:47:21tamasnagyBenzinkút üzemeltetés (55)cpp17Elfogadva 55/552ms508 KiB
// mol-os hotdog.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
size_t n, k;
int IndexMax = 1;
vector <pair<int, int>> benzinkut;
vector <int> dp;
vector <int> os;
vector <int> dads;

void solve() {
    for (int i = 1; i <= n; i++) {
        dp[i] = benzinkut[i].second;
        for (int j = 0; j<i; j++) {
            if (benzinkut[i].first - benzinkut[j].first >= k) {
                if (dp[j] + benzinkut[i].second > dp[i]) {
                    dp[i] = dp[j] + benzinkut[i].second;
                    os[i] = j;
                }
            }
        }
        if (dp[i] > dp[IndexMax]) {
            IndexMax = i;
        }
    }
    cout << dp[IndexMax] << endl;
    //    for(int i=1; i<=n; i++){
    //        cout<<dp[i]<<' '<<os[i]<<endl;
    //    }
}

void visszakeres() {
    int x = IndexMax;
    while (x != 0) {
        dads.push_back(x);
        x = os[x];
    }
    cout << dads.size() << ' ';
    for (int i = dads.size() - 1; i >= 0; i--) {
        cout << dads[i] << ' ';
    }
}

int main()
{
    cin >> n >> k;
    benzinkut.resize(n + 1);
    dp.resize(n + 1);
    os.resize(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> benzinkut[i].first >> benzinkut[i].second;
    }
    benzinkut[0].first = -1001;
    solve();
    visszakeres();
    return 0;
}

// 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ÖsszpontTesztVerdiktIdőMemória
base55/55
1Elfogadva0/01ms508 KiB
2Elfogadva0/02ms508 KiB
3Elfogadva3/31ms316 KiB
4Elfogadva3/31ms316 KiB
5Elfogadva3/31ms316 KiB
6Elfogadva3/31ms316 KiB
7Elfogadva3/31ms316 KiB
8Elfogadva3/31ms316 KiB
9Elfogadva3/31ms316 KiB
10Elfogadva3/31ms316 KiB
11Elfogadva3/31ms316 KiB
12Elfogadva3/31ms316 KiB
13Elfogadva4/42ms316 KiB
14Elfogadva4/42ms508 KiB
15Elfogadva5/52ms316 KiB
16Elfogadva6/62ms316 KiB
17Elfogadva6/62ms316 KiB