/*
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
\\ //
// 271828___182845__904523__53602__ \\
\\ 87___47____13______52____66__24_ //
// 97___75____72______47____09___36 \\
\\ 999595_____74______96____69___67 //
// 62___77____24______07____66__30_ \\
\\ 35___35____47______59____45713__ //
// \\
\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
*/
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <climits>
#include <algorithm>
#include <random>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <tuple>
#include <bitset>
#include <chrono>
#include <ctime>
#include <fstream>
#include <stack>
#include <cstdio>
using namespace std;
using ll = long long;
const int N = 3e5 + 5;
const ll mod = 1e9 + 7, inf = LLONG_MAX;
struct camp {
int x, g, d;
};
void solve() {
// pref_en[r] - pref_en[l - 1] >= x[r] - x[l - 1]
// pref_en[r] - x[r] >= pref_en[l - 1] - x[l - 1]
// x[r] - x[l] <= pref[r] - pref[l]
// pref[r] - x[r] >= pref[l] - pref[r]
int n; cin >> n;
vector<camp> v(n);
for (int i = 0; i < n; ++i) {
cin >> v[i].x >> v[i].g >> v[i].d;
}
vector<ll> pref(n + 1);
for (int i = 1; i <= n; ++i) {
pref[i] = pref[i - 1] + v[i - 1].d;
}
vector<ll> pref_en(n + 1), gold(n + 1);
for (int i = 1; i <= n; ++i) {
//pref_en[i] = pref[i] - v[i - 1].x;
gold[i] = gold[i - 1] + v[i - 1].g;
}
long long ans = 0;
//for (int i = 1; i <= n; ++i) cout << pref_en[i] << " \n"[i == n];
for (int i = 1; i <= n; ++i) {
//ans = max(ans, v[i - 1].g * 1ll);
for (int j = i; j <= n; ++j) {
if (pref[j] - v[j - 1].x >= pref[i - 1] - v[i - 1].x) ans = max(ans, gold[j] - gold[i - 1]);
}
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
//int t; cin >> t;
//while (t--)
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
356 KB |
Output is correct |
18 |
Correct |
2 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
376 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
10 ms |
588 KB |
Output is correct |
24 |
Correct |
10 ms |
484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
356 KB |
Output is correct |
18 |
Correct |
2 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
376 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
10 ms |
588 KB |
Output is correct |
24 |
Correct |
10 ms |
484 KB |
Output is correct |
25 |
Correct |
15 ms |
460 KB |
Output is correct |
26 |
Correct |
54 ms |
724 KB |
Output is correct |
27 |
Correct |
55 ms |
852 KB |
Output is correct |
28 |
Execution timed out |
1083 ms |
2988 KB |
Time limit exceeded |
29 |
Halted |
0 ms |
0 KB |
- |