| 22231 | 2026-01-14 18:16:26 | algopro | Benzinkút üzemeltetés (55) | cpp17 | Forditási hiba |
// UUID: 3072b4eb-ed99-4f6f-a978-423a6abdc4d8
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,k;
cin >> n >> k;
vector<pair<int,int>>bz(n);
vector<int>tav(n);
for(int i=0; i<n; i++){
cin >> bz[i].first >> bz[i].second;
tav[i]=bz[i].first;
}
vector<int>dp(n);
vector<bool>vsz(n, false);
dp[0]=bz[0].second;
int l=0;
for(int i=1; i<n; i++){
//int j;
while(bz[i].first-bz[l].first>=k && l<=i)l++;
int p = l - 1;
if (p >= 0) {
dp[i] = max(dp[i-1], bz[i].second + dp[prev]);
} else {
dp[i] = max(dp[i-1], bz[i].second);
}
if(dp[i]!=dp[i-1])vsz[i]=true;
//cout << dp[i] << " ";
}
cout<< dp[n-1] << '\n';
int maxi=0;
vector<int> ans;
int i=n-1;
while(i>=0){
if(vsz[i]){
ans.push_back(i+1);
int j=i-1;
while(j>=0 && bz[i].first-bz[j].first<k)j--;
i=j;
}
else i--;
}
reverse(ans.begin(), ans.end());
cout << ans.size() << " ";
for(int j=0; j<ans.size(); j++){cout << ans[j]<< " ";}
}
/*l=n-1;
for(int i=n-1; i>0; i-- ){
while(bz[i].first-bz[l].first>=k && l>=0)l--;
l++;
if(l<n){
if(dp[i]!=dp[l])maxi ++; }
else {l=n-1;}
}
cout << maxi << " ";
for(int i=n-1; i>0; i-- ){
while(bz[i].first-bz[l].first>=k && l>=0)l--;;
l++;
if(l<n){
if(dp[i]!=dp[l])cout << i+1 << " "; }
else l=n-1;
}*/open /var/local/lib/isolate/443/box/a.out: no such file or directory
main.cpp: In function 'int main()':
main.cpp:24:63: error: no match for 'operator[]' (operand types are 'std::vector<int>' and '<unresolved overloaded function type>')
24 | dp[i] = max(dp[i-1], bz[i].second + dp[prev]);
| ^
In file included from /usr/include/c++/12/vector:64,
from /usr/include/c++/12/functional:62,
from /usr/include/x86_64-linux-gnu/c++/12/bits/stdc++.h:71,
from main.cpp:2:
/usr/include/c++/12/bits/stl_vector.h:1121:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]'
1121 | operator[](size_type __n) _GLIBCXX_NOEXCEPT
| ^~~~~~~~
/usr/include/c++/12/bits/stl_vector.h:1121:28: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
1121 | operator[](size_type __n) _GLIBCXX_NOEXCEPT
| ~~~~~~~~~~^~~
/usr/include/c++/12/bits/stl_vector.h:1140:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](size_type) const [with _Tp = int; _Alloc = std::allocator<int>; const_reference = const int&; size_type = long unsigned int]'
1140 | operator[](size_type __n) const _GLIBCXX_NOEXCEPT
| ^~~~~~~~
/usr/include/c++/12/bits/stl_vector.h:1140:28: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
1140 | operator[](size_type __n) const _GLIBCXX_NOEXCEPT
| ~~~~~~~~~~^~~