254102026-02-19 21:05:01CzDaniMúzeumi őrökcpp17Runtime error 32/40187ms32000 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

signed main() {
    int n, e, u;
    cin >> n >> e >> u;
    vector<int> dp(u+1, 1e16), ut(u+1);
    vector<pair<int, int>> v(n+1);
    map<int, vector<pair<int, int>>> vp;
    for (int i = 1; i <= n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        if (b<e||a>u)continue;
        a=max(a,e);
        b=min(b,u);
        vp[a].push_back({i, c});
        v[i] = {a, b};
    }
    dp[e-1]=0;
    priority_queue<pair<int, int>> q;
    for (int i = e; i <= u; i++) {
        for (auto [a, b] : vp[i]) {
            q.push({-(dp[i-1]+b), a});
        }
        while (!q.empty()&&v[q.top().second].second<i)q.pop();
        if (!q.empty()) {
            dp[i]=-q.top().first;
            ut[i]=q.top().second;
        }
    }
    if (dp[u]>=1e15) {
        cout << -1;
        return 0;
    }
    vector<int> ansv;
    int x = ut[u];
    while (x!=0) {
        ansv.push_back(x);
        x=ut[v[x].first-1];
    }
    sort(ansv.begin(), ansv.end());
    cout << dp[u] << '\n';
    cout << ansv.size() << ' ';
    for (int y : ansv) cout << y << ' ';
}
SubtaskSumTestVerdictTimeMemory
base32/40
1Accepted0/01ms500 KiB
2Accepted0/027ms4404 KiB
3Accepted1/11ms316 KiB
4Accepted3/31ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms500 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Runtime error0/2175ms32000 KiB
11Runtime error0/2181ms32000 KiB
12Accepted2/22ms564 KiB
13Accepted2/27ms984 KiB
14Accepted3/328ms5476 KiB
15Accepted3/328ms5428 KiB
16Runtime error0/2187ms32000 KiB
17Runtime error0/2175ms32000 KiB
18Accepted2/21ms508 KiB
19Accepted2/21ms316 KiB
20Accepted2/21ms500 KiB
21Accepted2/21ms316 KiB