This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()
struct T {
ll pos, gold, cost;
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
T a[n];
ll ans = 0;
for (int i = 0; i < n; i++) {
cin >> a[i].pos >> a[i].gold >> a[i].cost;
ans = max(ans, a[i].gold);
}
ll l = 0, sumCost = a[0].cost, sumGold = a[0].gold;
for (int r = 1; r < n; r++) {
sumCost += a[r].cost;
sumGold += a[r].gold;
while (sumCost < a[r].pos - a[l].pos) {
sumCost -= a[l].cost;
sumGold -= a[l].gold;
l++;
}
ans = max(ans, sumGold);
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |