//Suleyman Atayew
#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#define N 1000010
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define inf 1000000007
#define pii pair <ll, ll>
using namespace std;
ll n;
ll T[N*4];
map <ll, ll> M;
ll E[N], P[N], G[N];
ll tap(ll pos, ll l, ll r, ll node)
{
if(r < pos) return 0;
if(l >= pos) return T[node];
return max(tap(pos, l, (l+r)/2, node*2), tap(pos, (l+r)/2+1, r, node*2+1));
}
void upd(ll pos, ll x, ll l, ll r, ll node)
{
if(l == r) {
T[node] = max(x, T[node]);
return;
}
if(pos <= (l+r)/2)
upd(pos, x, l, (l+r)/2, node*2);
else
upd(pos, x, (l+r)/2+1, r, node*2+1);
T[node] = max(T[node*2], T[node*2+1]);
}
int main()
{
cin >> n;
for(ll i = 1; i <= n; i++) {
cin >> P[i] >> G[i] >> E[i];
E[i] += E[i-1];
G[i] += G[i-1];
M[E[i] - P[i]] = 1;
M[E[i-1] - P[i]] = 1;
}
ll now = 0, cur = 0;
for(auto &i: M) i.ss = ++now;
for(ll i = n; i >= 1; i--) {
upd(M[E[i] - P[i]], G[i], 1, now, 1);
cur = max(tap(M[E[i-1] - P[i]], 1, now, 1) - G[i-1], cur);
}
cout << cur;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
4 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
632 KB |
Output is correct |
7 |
Correct |
12 ms |
504 KB |
Output is correct |
8 |
Correct |
4 ms |
504 KB |
Output is correct |
9 |
Correct |
6 ms |
632 KB |
Output is correct |
10 |
Correct |
6 ms |
760 KB |
Output is correct |
11 |
Correct |
16 ms |
1400 KB |
Output is correct |
12 |
Correct |
17 ms |
1400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
1400 KB |
Output is correct |
2 |
Correct |
22 ms |
2428 KB |
Output is correct |
3 |
Correct |
27 ms |
2552 KB |
Output is correct |
4 |
Correct |
134 ms |
11000 KB |
Output is correct |
5 |
Correct |
163 ms |
11208 KB |
Output is correct |
6 |
Correct |
381 ms |
22256 KB |
Output is correct |
7 |
Correct |
304 ms |
21148 KB |
Output is correct |
8 |
Correct |
316 ms |
21228 KB |
Output is correct |
9 |
Correct |
254 ms |
20984 KB |
Output is correct |
10 |
Correct |
260 ms |
20472 KB |
Output is correct |
11 |
Correct |
324 ms |
21436 KB |
Output is correct |
12 |
Correct |
301 ms |
21752 KB |
Output is correct |