#include <bits/stdc++.h>
#define MAX 10000000
using ll = long long;
struct node {
int left,right;
ll val;
};
const ll inf = (1LL<<60LL);
node mem[MAX*4];
int cur=1;
int alocar(void){
int x = cur++;
mem[x].val=inf;
return x;
}
int inicio = alocar();
ll query(ll l,ll r,ll la=-inf,ll ra=inf,ll pos=inicio){
if(!pos)return inf;
if(l>ra||r<la)return inf;
/// std::cout<<"Explora "<<la<<" "<<ra<<" "<<l<<" "<<r<<"\n";
if(la>=l&&ra<=r){
return mem[pos].val;
}
ll m = (la+(4LL*inf)+ra)/2LL;
m-=2LL*inf;
return std::min(query(l,r,la,m,mem[pos].left),query(l,r,m+1,ra,mem[pos].right));
}
void update(ll t,ll k,ll la=-inf,ll ra=inf,ll pos=inicio){
ll m = (la+(4LL*inf)+ra)/2LL;
m-=2LL*inf;
mem[pos].val=std::min(mem[pos].val,k);
/// std::cout<<"Alterando "<<la<<" "<<ra<<" "<<" "<<m<<" "<<mem[pos].val<<"\n";
if(la==ra)return;
if(t>m){
if(!mem[pos].right)mem[pos].right=alocar();
update(t,k,m+1,ra,mem[pos].right);
}else {
if(!mem[pos].left)mem[pos].left=alocar();
update(t,k,la,m,mem[pos].left);
}
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int N;
std::cin>>N;
ll resp=0;
ll prefouro=0;
ll prefener=0;
for(int i=0;i!=N;++i){
ll pos,gold,energy;
std::cin>>pos>>gold>>energy;
update(pos-prefener,prefouro);
/// std::cout<<"Upd "<<pos-1-prefener<<" "<<prefouro<<"\n";
prefener+=energy;
ll valor = -pos+prefener;
ll la = -valor,ra=inf;
ll ponto = query(std::min(la,ra),std::max(la,ra));
prefouro+=gold;
/// std::cout<<la<<" "<<ra<<" "<<valor<<" "<<prefouro<<" "<<ponto<<"\n";
resp=std::max(resp,prefouro-ponto);
}
std::cout<<resp<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
388 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
388 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
2 ms |
852 KB |
Output is correct |
19 |
Correct |
2 ms |
596 KB |
Output is correct |
20 |
Correct |
2 ms |
596 KB |
Output is correct |
21 |
Correct |
2 ms |
444 KB |
Output is correct |
22 |
Correct |
3 ms |
600 KB |
Output is correct |
23 |
Correct |
7 ms |
1832 KB |
Output is correct |
24 |
Correct |
8 ms |
1880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
388 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
2 ms |
852 KB |
Output is correct |
19 |
Correct |
2 ms |
596 KB |
Output is correct |
20 |
Correct |
2 ms |
596 KB |
Output is correct |
21 |
Correct |
2 ms |
444 KB |
Output is correct |
22 |
Correct |
3 ms |
600 KB |
Output is correct |
23 |
Correct |
7 ms |
1832 KB |
Output is correct |
24 |
Correct |
8 ms |
1880 KB |
Output is correct |
25 |
Correct |
5 ms |
1108 KB |
Output is correct |
26 |
Correct |
9 ms |
2008 KB |
Output is correct |
27 |
Correct |
11 ms |
3548 KB |
Output is correct |
28 |
Correct |
60 ms |
17160 KB |
Output is correct |
29 |
Correct |
52 ms |
17432 KB |
Output is correct |
30 |
Correct |
105 ms |
50680 KB |
Output is correct |
31 |
Correct |
99 ms |
34000 KB |
Output is correct |
32 |
Correct |
97 ms |
34128 KB |
Output is correct |
33 |
Correct |
86 ms |
17480 KB |
Output is correct |
34 |
Correct |
94 ms |
11696 KB |
Output is correct |
35 |
Correct |
112 ms |
24888 KB |
Output is correct |
36 |
Correct |
105 ms |
24764 KB |
Output is correct |