240722026-02-04 07:31:23tamasnagyBenzinkút üzemeltetés (55)cpp17Wrong answer 39/553ms508 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;
vector <pair<size_t, size_t>> benzinkut;
vector <size_t> dp;
vector <size_t> os;
vector <size_t> dads;

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

void visszakeres() {
    int x = n;
    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
SubtaskSumTestVerdictTimeMemory
base39/55
1Accepted0/01ms508 KiB
2Accepted0/03ms316 KiB
3Accepted3/31ms316 KiB
4Accepted3/31ms316 KiB
5Wrong answer0/31ms316 KiB
6Accepted3/31ms316 KiB
7Wrong answer0/31ms316 KiB
8Accepted3/31ms316 KiB
9Wrong answer0/31ms316 KiB
10Accepted3/31ms316 KiB
11Accepted3/31ms316 KiB
12Wrong answer0/32ms416 KiB
13Accepted4/42ms336 KiB
14Wrong answer0/42ms316 KiB
15Accepted5/53ms316 KiB
16Accepted6/63ms316 KiB
17Accepted6/63ms316 KiB