81012024-01-12 13:12:40TuruTamasBenzinkút üzemeltetés (55)cpp17Accepted 55/554ms7888 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
ifstream in_file("minta/be2.txt");
#define input in_file
#define INTHENAMEOFGOD
#else
#define input cin
#define INTHENAMEOFGOD \
    ios::sync_with_stdio(0); \
    cin.tie(0); \
    cout.tie(0);
#endif
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<ll, ll> pii;

struct megoldas {
    ll ertek;
    vi kutak;
};

ll N, K;
vi d, H;
vector<megoldas> opt;

int main() {
    input >> N >> K;
    d.resize(N);
    H.resize(N); 
    input >> d[0] >> H[0];
    opt.push_back((megoldas) {
        .ertek = H[0],
        .kutak = {0},
    });
    for (ll n = 1; n < N; n++) {
        input >> d[n] >> H[n];
        if (d[n] - K < d[0]) {
            auto elozo = opt.back();
            if (H[n] > elozo.ertek) {
                opt.push_back((megoldas) {
                    .ertek = H[n],
                    .kutak = {n},
                });
            } else {
                opt.push_back(opt.back());
            }
            continue;
        }
        ll i = lower_bound(d.begin()+1, d.begin()+n, d[n]-K) - d.begin();
        if (d[i] > d[n]-K) {
            i--;
        }
        assert(i >= 0);
        assert(d[i] <= d[n]-K);
        if (opt[i].ertek + H[n] > opt.back().ertek) {
            opt.push_back((megoldas) {
                .ertek = opt[i].ertek + H[n],
                .kutak = opt[i].kutak,
            }),
            opt.back().kutak.push_back(n);
        } else {
            opt.push_back(opt.back());
        }
    }
    cout << opt.back().ertek << "\n" << opt.back().kutak.size() << " ";
    for (ll kut : opt.back().kutak) {
        cout << kut+1 << " ";
    }
    cout << endl;
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/03ms1812 KiB
2Accepted0/04ms7164 KiB
3Accepted3/33ms2264 KiB
4Accepted3/33ms2424 KiB
5Accepted3/33ms2640 KiB
6Accepted3/33ms2728 KiB
7Accepted3/33ms2724 KiB
8Accepted3/33ms2728 KiB
9Accepted3/33ms2884 KiB
10Accepted3/33ms3136 KiB
11Accepted3/33ms3288 KiB
12Accepted3/33ms4328 KiB
13Accepted4/44ms5276 KiB
14Accepted4/44ms5588 KiB
15Accepted5/54ms6488 KiB
16Accepted6/64ms7388 KiB
17Accepted6/64ms7888 KiB