207782026-01-08 20:46:29szabelrBenzinkút üzemeltetés (55)cpp17Accepted 55/552ms508 KiB
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    vector<int>dp(n + 1, 0);
    vector<int>tavok;
    vector<int>res;
    for (int i = 1; i <= n; i++)
    {
        int t,h; cin >> t>>h;
        tavok.push_back(t);
        if (t - k < 0)
        {
            dp[i] = max(dp[i - 1], h);
        }
        else
        {
            auto it = upper_bound(tavok.begin(), tavok.begin()+(i-1), (t - k));
            int idx = distance(tavok.begin(), it);

            dp[i] = max(dp[i - 1], h + dp[idx]);
        }
    }
    int j = n;
    while (j > 0) {
        if (dp[j] != dp[j - 1]) {
            res.push_back(j);
            auto it = upper_bound(tavok.begin(), tavok.begin() + j - 1, tavok[j - 1] - k);
            j = distance(tavok.begin(), it);
        }
        else {
            j--;
        }
    }
    reverse(res.begin(), res.end());
    cout << dp[n] << endl;
    cout << res.size() << " ";
    for (auto x : res)
        cout << x << " ";
}
SubtaskSumTestVerdictTimeMemory
base55/55
1Accepted0/02ms316 KiB
2Accepted0/02ms508 KiB
3Accepted3/32ms316 KiB
4Accepted3/32ms316 KiB
5Accepted3/31ms316 KiB
6Accepted3/31ms316 KiB
7Accepted3/31ms316 KiB
8Accepted3/31ms376 KiB
9Accepted3/31ms316 KiB
10Accepted3/31ms316 KiB
11Accepted3/31ms316 KiB
12Accepted3/31ms316 KiB
13Accepted4/41ms500 KiB
14Accepted4/41ms316 KiB
15Accepted5/51ms316 KiB
16Accepted6/61ms316 KiB
17Accepted6/61ms316 KiB