#include <iostream>
#include <algorithm>
#define MAX_N 100000
#define MAX_G 100000000000000
using namespace std;
struct val_and_poz {
int poz;
long long val;
bool operator < (const val_and_poz &a) const {
return val < a.val;
}
};
struct AIB {
long long aib[2 * MAX_N + 1];
void init() {
int i;
for ( i = 0; i <= 2 * MAX_N; i++ )
aib[i] = MAX_G + 1;
}
long long query( int i ) {
long long minG;
minG = MAX_G + 1;
while ( i > 0 ) {
minG = min( minG, aib[i] );
i -= (i & -i);
}
return minG;
}
void update( int i, long long x ) {
while ( i <= 2 * MAX_N ) {
aib[i] = min( aib[i], x );
i += (i & -i);
}
}
};
int x[MAX_N + 1], g[MAX_N + 1], d[MAX_N + 1], small[MAX_N + 1], big[MAX_N + 1];
long long sg[MAX_N + 1], sd[MAX_N + 1];
val_and_poz norm[2 * MAX_N];
AIB gold;
signed main() {
int n, a, i;
long long maxG;
cin >> n;
for ( i = 1; i <= n; i++ )
cin >> x[i] >> g[i] >> d[i];
for ( i = 1; i <= n; i++ ) {
sg[i] = sg[i - 1] + g[i];
sd[i] = sd[i - 1] + d[i];
}
for ( i = 0; i < n; i++ )
norm[i] = { i, sd[i] - x[i + 1] };
for ( i = 0; i < n; i++ )
norm[n + i] = { n + i, sd[i + 1] - x[i + 1] };
sort( norm, norm + 2 * n );
a = 1;
for ( i = 0; i < 2 * n; i++ ) {
if ( norm[i].poz < n )
small[norm[i].poz + 1] = a;
else
big[norm[i].poz - n + 1] = a;
if ( i < 2 * n - 1 && norm[i].val != norm[i + 1].val )
a++;
}
maxG = 0;
gold.init();
for ( i = 1; i <= n; i++ ) {
gold.update( small[i], sg[i - 1] );
maxG = max( maxG, sg[i] - gold.query( big[i] ) );
}
cout << maxG;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1868 KB |
Output is correct |
2 |
Correct |
1 ms |
1868 KB |
Output is correct |
3 |
Correct |
1 ms |
1868 KB |
Output is correct |
4 |
Correct |
1 ms |
1868 KB |
Output is correct |
5 |
Correct |
1 ms |
1868 KB |
Output is correct |
6 |
Correct |
1 ms |
1868 KB |
Output is correct |
7 |
Correct |
1 ms |
1868 KB |
Output is correct |
8 |
Correct |
1 ms |
1868 KB |
Output is correct |
9 |
Correct |
1 ms |
1868 KB |
Output is correct |
10 |
Correct |
2 ms |
1868 KB |
Output is correct |
11 |
Correct |
1 ms |
1868 KB |
Output is correct |
12 |
Correct |
1 ms |
1868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1868 KB |
Output is correct |
2 |
Correct |
1 ms |
1868 KB |
Output is correct |
3 |
Correct |
1 ms |
1868 KB |
Output is correct |
4 |
Correct |
1 ms |
1868 KB |
Output is correct |
5 |
Correct |
1 ms |
1868 KB |
Output is correct |
6 |
Correct |
1 ms |
1868 KB |
Output is correct |
7 |
Correct |
1 ms |
1868 KB |
Output is correct |
8 |
Correct |
1 ms |
1868 KB |
Output is correct |
9 |
Correct |
1 ms |
1868 KB |
Output is correct |
10 |
Correct |
2 ms |
1868 KB |
Output is correct |
11 |
Correct |
1 ms |
1868 KB |
Output is correct |
12 |
Correct |
1 ms |
1868 KB |
Output is correct |
13 |
Correct |
1 ms |
1868 KB |
Output is correct |
14 |
Correct |
1 ms |
1868 KB |
Output is correct |
15 |
Correct |
2 ms |
1868 KB |
Output is correct |
16 |
Correct |
2 ms |
1868 KB |
Output is correct |
17 |
Correct |
2 ms |
1868 KB |
Output is correct |
18 |
Correct |
3 ms |
1868 KB |
Output is correct |
19 |
Correct |
2 ms |
1868 KB |
Output is correct |
20 |
Correct |
2 ms |
1868 KB |
Output is correct |
21 |
Correct |
2 ms |
1996 KB |
Output is correct |
22 |
Correct |
3 ms |
1996 KB |
Output is correct |
23 |
Correct |
7 ms |
2160 KB |
Output is correct |
24 |
Correct |
7 ms |
2124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1868 KB |
Output is correct |
2 |
Correct |
1 ms |
1868 KB |
Output is correct |
3 |
Correct |
1 ms |
1868 KB |
Output is correct |
4 |
Correct |
1 ms |
1868 KB |
Output is correct |
5 |
Correct |
1 ms |
1868 KB |
Output is correct |
6 |
Correct |
1 ms |
1868 KB |
Output is correct |
7 |
Correct |
1 ms |
1868 KB |
Output is correct |
8 |
Correct |
1 ms |
1868 KB |
Output is correct |
9 |
Correct |
1 ms |
1868 KB |
Output is correct |
10 |
Correct |
2 ms |
1868 KB |
Output is correct |
11 |
Correct |
1 ms |
1868 KB |
Output is correct |
12 |
Correct |
1 ms |
1868 KB |
Output is correct |
13 |
Correct |
1 ms |
1868 KB |
Output is correct |
14 |
Correct |
1 ms |
1868 KB |
Output is correct |
15 |
Correct |
2 ms |
1868 KB |
Output is correct |
16 |
Correct |
2 ms |
1868 KB |
Output is correct |
17 |
Correct |
2 ms |
1868 KB |
Output is correct |
18 |
Correct |
3 ms |
1868 KB |
Output is correct |
19 |
Correct |
2 ms |
1868 KB |
Output is correct |
20 |
Correct |
2 ms |
1868 KB |
Output is correct |
21 |
Correct |
2 ms |
1996 KB |
Output is correct |
22 |
Correct |
3 ms |
1996 KB |
Output is correct |
23 |
Correct |
7 ms |
2160 KB |
Output is correct |
24 |
Correct |
7 ms |
2124 KB |
Output is correct |
25 |
Correct |
5 ms |
2124 KB |
Output is correct |
26 |
Correct |
9 ms |
2508 KB |
Output is correct |
27 |
Correct |
10 ms |
2560 KB |
Output is correct |
28 |
Correct |
56 ms |
5300 KB |
Output is correct |
29 |
Correct |
77 ms |
5172 KB |
Output is correct |
30 |
Correct |
150 ms |
8388 KB |
Output is correct |
31 |
Correct |
125 ms |
10104 KB |
Output is correct |
32 |
Correct |
109 ms |
10372 KB |
Output is correct |
33 |
Correct |
98 ms |
10052 KB |
Output is correct |
34 |
Correct |
105 ms |
10040 KB |
Output is correct |
35 |
Correct |
111 ms |
10724 KB |
Output is correct |
36 |
Correct |
123 ms |
10900 KB |
Output is correct |