207762026-01-08 20:43:45szabelrBenzinkút üzemeltetés (55)cpp17Wrong answer 8/551ms508 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 x = upper_bound(tavok.begin(), tavok.end(), (t - k));
            if ((x - tavok.begin() - 1)<0)
                dp[i] = max(dp[i - 1], h);
            else
                dp[i] = max(dp[i - 1], h + dp[x - tavok.begin()-1]);
        }
    }
    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
base8/55
1Accepted0/01ms316 KiB
2Wrong answer0/01ms508 KiB
3Partially correct1/31ms316 KiB
4Partially correct1/31ms336 KiB
5Accepted3/31ms316 KiB
6Wrong answer0/31ms316 KiB
7Accepted3/31ms316 KiB
8Wrong answer0/31ms508 KiB
9Wrong answer0/31ms316 KiB
10Wrong answer0/31ms316 KiB
11Wrong answer0/31ms316 KiB
12Wrong answer0/31ms500 KiB
13Wrong answer0/41ms428 KiB
14Wrong answer0/41ms316 KiB
15Wrong answer0/51ms316 KiB
16Wrong answer0/61ms316 KiB
17Wrong answer0/61ms316 KiB