#include <bits/stdc++.h>
#define ll long long
#define left (h<<1),l,((l+r)>>1)
#define right ((h<<1)|1),((l+r)>>1) + 1,r
#define pb push_back
#define int ll
using namespace std;
const int N = 200005,inf = 1e18;
map <int,int> mp;
int pe[N],pg[N],t[4*N],a[N];
vector <int> v;
void build(int h,int l,int r){
t[h] = inf;
if (l == r) return;
build(left),build(right);
t[h] = min(t[h*2],t[h*2+1]);
}
void upd(int h,int l,int r,int idx,int val){
if (l == r){
t[h] = min(t[h],val);
return;
}
if ((l + r)/2 < idx) upd(right,idx,val);
else upd(left,idx,val);
t[h] = min(t[h*2],t[h*2+1]);
}
int get(int h,int l,int r,int L,int R){
if (r < L || R < l) return inf;
if (L <= l && r <= R) return t[h];
return min(get(left,L,R),get(right,L,R));
}
signed main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n;
cin>>n;
for (int i = 1; i <= n; i++){
int g,e;
cin>>a[i]>>g>>e;
pe[i] = pe[i - 1] + e;
pg[i] = pg[i - 1] + g;
v.pb(pe[i] - a[i]);
v.pb(pe[i - 1] - a[i]);
}
sort(v.begin(),v.end());
for (int i=0;i<v.size();i++){
if (!i) mp[v[i]] = 1;
else if (v[i] == v[i - 1]) mp[v[i]] = mp[v[i - 1]];
else mp[v[i]] = mp[v[i - 1]] + 1;
}
int lm = 200000,ans=0;
build(1,1,lm);
for (int i = 1; i <= n; i++){
upd(1,1,lm,mp[pe[i - 1] - a[i]],i);
int l = get(1,1,lm,1,mp[pe[i] - a[i]]);
if (l != inf) ans=max(ans,pg[i] - pg[l - 1]);
}
cout<<ans;
}
Compilation message
divide.cpp: In function 'int main()':
divide.cpp:50:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i=0;i<v.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4428 KB |
Output is correct |
2 |
Correct |
3 ms |
4428 KB |
Output is correct |
3 |
Correct |
3 ms |
4436 KB |
Output is correct |
4 |
Correct |
3 ms |
4436 KB |
Output is correct |
5 |
Correct |
3 ms |
4436 KB |
Output is correct |
6 |
Correct |
3 ms |
4436 KB |
Output is correct |
7 |
Correct |
3 ms |
4436 KB |
Output is correct |
8 |
Correct |
3 ms |
4436 KB |
Output is correct |
9 |
Correct |
3 ms |
4436 KB |
Output is correct |
10 |
Correct |
4 ms |
4436 KB |
Output is correct |
11 |
Correct |
3 ms |
4436 KB |
Output is correct |
12 |
Correct |
4 ms |
4436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4428 KB |
Output is correct |
2 |
Correct |
3 ms |
4428 KB |
Output is correct |
3 |
Correct |
3 ms |
4436 KB |
Output is correct |
4 |
Correct |
3 ms |
4436 KB |
Output is correct |
5 |
Correct |
3 ms |
4436 KB |
Output is correct |
6 |
Correct |
3 ms |
4436 KB |
Output is correct |
7 |
Correct |
3 ms |
4436 KB |
Output is correct |
8 |
Correct |
3 ms |
4436 KB |
Output is correct |
9 |
Correct |
3 ms |
4436 KB |
Output is correct |
10 |
Correct |
4 ms |
4436 KB |
Output is correct |
11 |
Correct |
3 ms |
4436 KB |
Output is correct |
12 |
Correct |
4 ms |
4436 KB |
Output is correct |
13 |
Correct |
3 ms |
4424 KB |
Output is correct |
14 |
Correct |
3 ms |
4436 KB |
Output is correct |
15 |
Correct |
4 ms |
4432 KB |
Output is correct |
16 |
Correct |
4 ms |
4568 KB |
Output is correct |
17 |
Correct |
4 ms |
4564 KB |
Output is correct |
18 |
Correct |
4 ms |
4692 KB |
Output is correct |
19 |
Correct |
4 ms |
4564 KB |
Output is correct |
20 |
Correct |
4 ms |
4564 KB |
Output is correct |
21 |
Correct |
5 ms |
4692 KB |
Output is correct |
22 |
Correct |
5 ms |
4720 KB |
Output is correct |
23 |
Correct |
9 ms |
5396 KB |
Output is correct |
24 |
Correct |
8 ms |
5380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4428 KB |
Output is correct |
2 |
Correct |
3 ms |
4428 KB |
Output is correct |
3 |
Correct |
3 ms |
4436 KB |
Output is correct |
4 |
Correct |
3 ms |
4436 KB |
Output is correct |
5 |
Correct |
3 ms |
4436 KB |
Output is correct |
6 |
Correct |
3 ms |
4436 KB |
Output is correct |
7 |
Correct |
3 ms |
4436 KB |
Output is correct |
8 |
Correct |
3 ms |
4436 KB |
Output is correct |
9 |
Correct |
3 ms |
4436 KB |
Output is correct |
10 |
Correct |
4 ms |
4436 KB |
Output is correct |
11 |
Correct |
3 ms |
4436 KB |
Output is correct |
12 |
Correct |
4 ms |
4436 KB |
Output is correct |
13 |
Correct |
3 ms |
4424 KB |
Output is correct |
14 |
Correct |
3 ms |
4436 KB |
Output is correct |
15 |
Correct |
4 ms |
4432 KB |
Output is correct |
16 |
Correct |
4 ms |
4568 KB |
Output is correct |
17 |
Correct |
4 ms |
4564 KB |
Output is correct |
18 |
Correct |
4 ms |
4692 KB |
Output is correct |
19 |
Correct |
4 ms |
4564 KB |
Output is correct |
20 |
Correct |
4 ms |
4564 KB |
Output is correct |
21 |
Correct |
5 ms |
4692 KB |
Output is correct |
22 |
Correct |
5 ms |
4720 KB |
Output is correct |
23 |
Correct |
9 ms |
5396 KB |
Output is correct |
24 |
Correct |
8 ms |
5380 KB |
Output is correct |
25 |
Correct |
8 ms |
5344 KB |
Output is correct |
26 |
Correct |
14 ms |
6140 KB |
Output is correct |
27 |
Correct |
14 ms |
6236 KB |
Output is correct |
28 |
Correct |
70 ms |
13580 KB |
Output is correct |
29 |
Correct |
69 ms |
13900 KB |
Output is correct |
30 |
Correct |
146 ms |
23744 KB |
Output is correct |
31 |
Correct |
136 ms |
22492 KB |
Output is correct |
32 |
Correct |
135 ms |
22704 KB |
Output is correct |
33 |
Correct |
137 ms |
22464 KB |
Output is correct |
34 |
Correct |
142 ms |
22076 KB |
Output is correct |
35 |
Correct |
135 ms |
23000 KB |
Output is correct |
36 |
Correct |
139 ms |
23132 KB |
Output is correct |