70712023-12-29 11:56:451478Benzinkút üzemeltetés (55)cpp17Accepted 55/553ms4000 KiB
#include <bits/stdc++.h>  
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
 
int main()
{
    //ifstream cin("in.txt");
    int n, k;
    cin >> n >> k;
    
    vector<int> d(n + 1);
    vector<int> p(n + 1);

    for(int i = 1; i <= n; i++){
        cin >> d[i] >> p[i];
    }

    vector<int> dp(n + 1);
    vector<int> anc(n + 1);
    vector<int> jump(n + 1);


    for(int i = 1; i <= n; i++){
        int j = i - 1;
        while(j >= 1 && d[i] - d[j] < k){
            j--;
        }
        if(dp[i - 1] > dp[j] + p[i]){
            dp[i] = dp[i - 1];
            if(jump[i - 1] == 0){
                jump[i] = i - 1;
            }
            else{
                jump[i] = jump[i - 1];
            }
        }
        else{
            dp[i] = dp[j] + p[i];
            anc[i] = j;
        }
    }

    cout << dp[n] << '\n';
    stack<int> s;
    int i = n;
    while(i > 0){
        if(anc[i] == 0 && jump[i] != 0){
            i = jump[i];
        }
        else{
            s.push(i);
            i = anc[i];
        }
    }
    cout << s.size() << " ";
    while(!s.empty()){
        cout << s.top() << " ";
        s.pop();
    }


    
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1812 KiB
2Accepted0/03ms2032 KiB
3Accepted3/33ms2480 KiB
4Accepted3/33ms2404 KiB
5Accepted3/33ms2496 KiB
6Accepted3/33ms2620 KiB
7Accepted3/33ms2704 KiB
8Accepted3/33ms2948 KiB
9Accepted3/33ms3220 KiB
10Accepted3/33ms3172 KiB
11Accepted3/33ms3268 KiB
12Accepted3/33ms3344 KiB
13Accepted4/43ms3412 KiB
14Accepted4/43ms3524 KiB
15Accepted5/53ms3656 KiB
16Accepted6/63ms3748 KiB
17Accepted6/63ms4000 KiB