240762026-02-04 07:38:54tamasnagyBenzinkút üzemeltetés (55)cpp17Compilation error
// 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; 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 {
                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) {
    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(Indexmax);
    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
Compilation error
open /var/local/lib/isolate/422/box/a.out: no such file or directory
main.cpp: In function 'void solve()':
main.cpp:35:25: error: a function-definition is not allowed here before '{' token
   35 | void visszakeres(int x) {
      |                         ^
main.cpp:46:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   46 | int main()
      |         ^~
main.cpp:46:9: note: remove parentheses to default-initialize a variable
   46 | int main()
      |         ^~
      |         --
main.cpp:46:9: note: or replace parentheses with braces to value-initialize a variable
main.cpp:47:1: error: a function-definition is not allowed here before '{' token
   47 | {
      | ^
main.cpp:59:2: error: expected '}' at end of input
   59 | }
      |  ^
main.cpp:15:14: note: to match this '{'
   15 | void solve() {
      |              ^