133712025-01-07 17:25:46marhaporkoltBenzinkút üzemeltetés (55)cpp17Wrong answer 31/552ms432 KiB
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    vector<int> h(n);
    for (int i=0; i<n; i++){
        cin>>v[i]>>h[i];
    }
    vector<int> ans;
    int haszon=0;
    vector<int> dp(n);
    dp[0]=h[0];
    for (int i=1; i<n; i++){
        int maxi=0;
        int j=0;
        while (v[j]<=v[i]-k){
            if (dp[j]>maxi){
                maxi=dp[j];
            }
            j++;
        }
        dp[i]=maxi+h[i];
    }
    haszon=dp[n-1];
    cout<<haszon<<endl;
    for (int i=n-1; i>=0; i--){
        if (haszon==dp[i]){
            ans.push_back(i+1);
            haszon-=h[i];
        }
    }
    cout<<ans.size()<<" ";
    reverse(ans.begin(),ans.end());
    for (auto i:ans){
        cout<<i<<" ";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base31/55
1Accepted0/01ms316 KiB
2Accepted0/02ms316 KiB
3Accepted3/31ms316 KiB
4Accepted3/31ms316 KiB
5Wrong answer0/31ms316 KiB
6Accepted3/31ms316 KiB
7Wrong answer0/31ms316 KiB
8Accepted3/31ms316 KiB
9Wrong answer0/31ms348 KiB
10Accepted3/31ms316 KiB
11Accepted3/31ms316 KiB
12Wrong answer0/31ms316 KiB
13Partially correct2/41ms432 KiB
14Wrong answer0/41ms316 KiB
15Partially correct2/52ms316 KiB
16Partially correct3/62ms428 KiB
17Accepted6/62ms316 KiB