| 24074 | 2026-02-04 07:36:00 | tamasnagy | Benzinkút üzemeltetés (55) | cpp17 | Forditási hiba |
// 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<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;
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 = 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
open /var/local/lib/isolate/416/box/a.out: no such file or directory
main.cpp: In function 'void solve()':
main.cpp:35:20: error: a function-definition is not allowed here before '{' token
35 | void visszakeres() {
| ^
main.cpp:47:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
47 | int main()
| ^~
main.cpp:47:9: note: remove parentheses to default-initialize a variable
47 | int main()
| ^~
| --
main.cpp:47:9: note: or replace parentheses with braces to value-initialize a variable
main.cpp:48:1: error: a function-definition is not allowed here before '{' token
48 | {
| ^
main.cpp:60:2: error: expected '}' at end of input
60 | }
| ^
main.cpp:15:14: note: to match this '{'
15 | void solve() {
| ^