38922023-03-03 18:36:33Erik_GepardBenzinkút üzemeltetés (55)cpp17Accepted 55/553ms4288 KiB
#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n, k;
    cin>>n>>k;
    vector<pair<int, int>> kut(n+1, {0, 0});
    for(pair<int, int> &x : kut) cin>>x.first>>x.second;
    vector<int> dp(n+1);
    vector<int> parent(n+1);
    for(int i=0; i<n; i++){
        dp[i]=kut[i].second;
        parent[i]=i;
        for(int j=0; j<i; j++){
            if(kut[i].first-kut[j].first>=k){
                if(dp[i]<dp[j]+kut[i].second){
                    dp[i]=dp[j]+kut[i].second;
                    parent[i]=j;
                }
            }
        }
    }
    int ans=0, ansh=0;
    for(int i=0; i<n; i++){
        if(dp[i]>ans){
            ans=dp[i];
            ansh=i;
        }
    }
    stack<int> val;
    int curr=ansh;
    while(curr!=parent[curr]){
        val.push(curr+1);
        curr=parent[curr];
    }
    cout<<ans<<"\n"<<val.size()+1<<" "<<curr+1<<" ";
    while(!val.empty()){
        cout<<val.top()<<" ";
        val.pop();
    }
    return;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1828 KiB
2Accepted0/03ms2072 KiB
3Accepted3/33ms2232 KiB
4Accepted3/33ms2444 KiB
5Accepted3/33ms2664 KiB
6Accepted3/33ms2868 KiB
7Accepted3/32ms2948 KiB
8Accepted3/33ms3184 KiB
9Accepted3/33ms3400 KiB
10Accepted3/32ms3476 KiB
11Accepted3/33ms3608 KiB
12Accepted3/33ms3700 KiB
13Accepted4/43ms3920 KiB
14Accepted4/43ms3952 KiB
15Accepted5/53ms4032 KiB
16Accepted6/63ms4288 KiB
17Accepted6/63ms4244 KiB