Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- const ll COST = 1e9;
- struct Exp {
- int l, r, c;
- Exp() {l = r = c = 0;}
- };
- ll dp[(int)2e6 + 1];
- deque<ll> deq[107];
- signed main() {
- #ifdef LOCAL
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- Exp exp[107];
- ll n, a;
- cin >> n >> a;
- for (int i = 0; i < n; ++i)
- cin >> exp[i].l >> exp[i].r >> exp[i].c;
- for (int i = a; i >= 0; --i) {
- dp[i] = i * COST;
- for (int j = 0; j < n; ++j) {
- if (i + exp[j].l <= a) {
- while (!deq[j].empty() && deq[j].back() > dp[i + exp[j].l])
- deq[j].pop_back();
- deq[j].push_back(dp[i + exp[j].l]);
- }
- if ((i + exp[j].r + 1) <= a) {
- if (!deq[j].empty() && deq[j].front() == dp[i + exp[j].r + 1])
- deq[j].pop_front();
- }
- }
- for (int j = 0; j < n; ++j) {
- if (!deq[j].empty() && (i + exp[j].r) <= a)
- dp[i] = max(dp[i], deq[j].front() - exp[j].c);
- }
- }
- cout << dp[0];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement