#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 1;
int n , ans = 0;
vector<int> x(N) , g(N) , d(N);
void solve(int l , int r){
if(l > r){
return;
}
int m = (l + r) / 2;
for(int L = l;L <= m;L ++){
for(int R = m;R <= r;R ++){
int e = 0 , s = 0;
for(int i = L;i <= R;i ++){
e += d[i];
s += g[i];
}
if(e == x[R] - x[L] + 1){
ans = max(ans , s);
}
}
}
solve(l , m - 1);
solve(m + 1 , r);
}
main(){
cin >> n;
for(int i = 1;i <= n;i ++){
cin >> x[i] >> g[i] >> d[i];
}
x[n + 1] = 1e15;
x[0] = -1e15;
//solve(1 , n);
for(int L = 1;L <= n;L ++){
for(int R = L;R <= n;R ++){
int s = 0 , e = 0;
for(int i = L;i <= R;i ++){
e += d[i];
s += g[i];
}
if(x[R + 1] - x[L - 1] >= e && e >= x[R] - x[L]){
ans = max(ans , s);
}
}
}
cout << ans << endl;
}
Compilation message
divide.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
27 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2712 KB |
Output is correct |
6 |
Correct |
2 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2804 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2712 KB |
Output is correct |
6 |
Correct |
2 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2804 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2648 KB |
Output is correct |
13 |
Correct |
2 ms |
2652 KB |
Output is correct |
14 |
Correct |
2 ms |
2652 KB |
Output is correct |
15 |
Correct |
9 ms |
2812 KB |
Output is correct |
16 |
Correct |
22 ms |
2652 KB |
Output is correct |
17 |
Correct |
44 ms |
2652 KB |
Output is correct |
18 |
Correct |
101 ms |
2652 KB |
Output is correct |
19 |
Correct |
63 ms |
2800 KB |
Output is correct |
20 |
Correct |
62 ms |
2652 KB |
Output is correct |
21 |
Correct |
218 ms |
2796 KB |
Output is correct |
22 |
Correct |
463 ms |
2808 KB |
Output is correct |
23 |
Execution timed out |
1060 ms |
2908 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2712 KB |
Output is correct |
6 |
Correct |
2 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2804 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
2648 KB |
Output is correct |
13 |
Correct |
2 ms |
2652 KB |
Output is correct |
14 |
Correct |
2 ms |
2652 KB |
Output is correct |
15 |
Correct |
9 ms |
2812 KB |
Output is correct |
16 |
Correct |
22 ms |
2652 KB |
Output is correct |
17 |
Correct |
44 ms |
2652 KB |
Output is correct |
18 |
Correct |
101 ms |
2652 KB |
Output is correct |
19 |
Correct |
63 ms |
2800 KB |
Output is correct |
20 |
Correct |
62 ms |
2652 KB |
Output is correct |
21 |
Correct |
218 ms |
2796 KB |
Output is correct |
22 |
Correct |
463 ms |
2808 KB |
Output is correct |
23 |
Execution timed out |
1060 ms |
2908 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |