80892024-01-12 12:38:07TuruTamasBenzinkút üzemeltetés (55)cpp17Wrong answer 12/554ms8076 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
ifstream in_file("minta/be3.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();
        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
base12/55
1Accepted0/03ms1808 KiB
2Wrong answer0/04ms7132 KiB
3Accepted3/33ms2272 KiB
4Accepted3/32ms2388 KiB
5Accepted3/33ms2432 KiB
6Wrong answer0/33ms2540 KiB
7Accepted3/33ms2640 KiB
8Wrong answer0/32ms2748 KiB
9Wrong answer0/33ms2764 KiB
10Wrong answer0/33ms3024 KiB
11Wrong answer0/33ms3264 KiB
12Wrong answer0/33ms4280 KiB
13Wrong answer0/43ms4992 KiB
14Wrong answer0/44ms5528 KiB
15Wrong answer0/54ms6600 KiB
16Wrong answer0/64ms7568 KiB
17Wrong answer0/64ms8076 KiB