207732026-01-08 20:37:38szabelrBenzinkút üzemeltetés (55)cpp17Wrong answer 6/55300ms508 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 = lower_bound(tavok.begin(), tavok.end(), (t - k));
            dp[i] = max(dp[i - 1], h + dp[x - tavok.begin()]);
        }
    }
    int j = n,x;
    while (j > 0)
    {
        if (dp[j] == dp[j - 1])
            j--;
        else
        {
            res.push_back(j);
            x = j - 1;
            while (x > 0 and dp[j - 1] - dp[x - 1] < k)
                x--;
        }
        j = x;
    }
    reverse(res.begin(), res.end());
    cout << dp[n] << endl;
    cout << res.size() << " ";
    for (auto x : res)
        cout << x << " ";
}
SubtaskSumTestVerdictTimeMemory
base6/55
1Accepted0/01ms316 KiB
2Wrong answer0/01ms316 KiB
3Accepted3/31ms316 KiB
4Accepted3/31ms316 KiB
5Time limit exceeded0/3298ms316 KiB
6Wrong answer0/31ms316 KiB
7Time limit exceeded0/3300ms316 KiB
8Wrong answer0/31ms500 KiB
9Time limit exceeded0/3300ms316 KiB
10Time limit exceeded0/3300ms316 KiB
11Wrong answer0/31ms316 KiB
12Time limit exceeded0/3289ms508 KiB
13Wrong answer0/41ms316 KiB
14Time limit exceeded0/4300ms316 KiB
15Wrong answer0/51ms316 KiB
16Time limit exceeded0/6300ms316 KiB
17Wrong answer0/61ms316 KiB