//{ <defines>
#ifndef _LOCAL
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
#endif
#include <bits/stdc++.h>
using namespace std;
#define fr(i, n) for(int i = 0; i < n; ++i)
#define fo(n) fr(i, n)
#define re return
#define ef else if
#define ifn(x) if(!(x))
#define _ << ' ' <<
#define ft first
#define sd second
#define ve vector
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define pw(x) (1 << (x))
#define PW(x) (1ll << (x))
#define bnd(x) x.begin(), x.end()
#define clr(x, y) memset(x, y, sizeof x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef ve<int> vi;
const int oo = 2e9;
const ll OO = 4e18;
//const ld pi = arg(complex<ld>(-1, 0));
//const ld pi2 = pi + pi;
const int md = 0x3b800001;
const int MD = 1e9 + 7;
inline ll time() {re chrono :: system_clock().now().time_since_epoch().count();}
mt19937 rnd(time());
mt19937_64 RND(time());
template<typename t> inline void umin(t &a, t b) {a = min(a, b);}
template<typename t> inline void umax(t &a, t b) {a = max(a, b);}
//} </defines>
const int N = 2e5 + 228;
ll d[N], g[N], e[N], c[N];
int n, x[N], fe[N];
void upd(int &a, int b) {a < 0 ? a = b : b < 0 ? a = a : a > b ? a = b : 0;}
void fupd(int i, int v) {for(i++; i < N; i += i & -i) upd(fe[i], v);}
int fget(int i) {int v = -1; for(i++; i; i -= i & -i) upd(v, fe[i]); re v;}
#define f for(int i = 1; i <= n; ++i)
void solve() {
clr(fe, -1);
cin >> n;
f cin >> x[i] >> g[i] >> d[i];
partial_sum(g + 1, g + n + 1, g + 1);
partial_sum(d + 1, d + n + 1, d + 1);
// if(n <= 100) {
// ll cor = 0;
// f fr(j, i + 1) if(j && d[i] - d[j - 1] >= x[i] - x[j]) umax(cor, g[i] - g[j - 1]);
// re void(cout << cor << endl);
// }
f c[i] = d[i] - x[i];
f e[i] = d[i - 1] - x[i];
ll *p[n + n];
fo(n) p[i] = &c[i + 1];
fo(n) p[n + i] = &e[i + 1];
sort(p, p + n + n, [] (ll *a, ll *b) {re *a < *b;});
int u[n + n];
fo(n + n) u[i] = i ? u[i - 1] + (*p[i - 1] != *p[i]) : 1;
fo(n + n) *p[i] = u[i];
ll ans = 0;
f {
fupd(e[i], i);
int h = fget(c[i]);
if(~h) umax(ans, g[i] - g[h - 1]);
}
cout << ans << endl;
}
int main() {
#ifdef _LOCAL
freopen("in.txt", "r", stdin);
int tests; cin >> tests;
fo(tests) {
cerr << "case #" << i+1 << endl;
solve();
}
#else
// freopen("divide.in", "r", stdin);
// freopen("divide.out", "w", stdout);
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
#endif
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1144 KB |
Output is correct |
2 |
Correct |
3 ms |
1144 KB |
Output is correct |
3 |
Correct |
3 ms |
1144 KB |
Output is correct |
4 |
Correct |
3 ms |
1148 KB |
Output is correct |
5 |
Correct |
3 ms |
1220 KB |
Output is correct |
6 |
Correct |
3 ms |
1148 KB |
Output is correct |
7 |
Correct |
3 ms |
1144 KB |
Output is correct |
8 |
Correct |
3 ms |
1144 KB |
Output is correct |
9 |
Correct |
3 ms |
1144 KB |
Output is correct |
10 |
Correct |
3 ms |
1144 KB |
Output is correct |
11 |
Correct |
3 ms |
1144 KB |
Output is correct |
12 |
Correct |
3 ms |
1216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1144 KB |
Output is correct |
2 |
Correct |
3 ms |
1144 KB |
Output is correct |
3 |
Correct |
3 ms |
1144 KB |
Output is correct |
4 |
Correct |
3 ms |
1144 KB |
Output is correct |
5 |
Correct |
3 ms |
1272 KB |
Output is correct |
6 |
Correct |
4 ms |
1272 KB |
Output is correct |
7 |
Correct |
3 ms |
1272 KB |
Output is correct |
8 |
Correct |
3 ms |
1272 KB |
Output is correct |
9 |
Correct |
8 ms |
1272 KB |
Output is correct |
10 |
Correct |
4 ms |
1272 KB |
Output is correct |
11 |
Correct |
6 ms |
1528 KB |
Output is correct |
12 |
Correct |
6 ms |
1528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1532 KB |
Output is correct |
2 |
Correct |
8 ms |
1784 KB |
Output is correct |
3 |
Correct |
9 ms |
1884 KB |
Output is correct |
4 |
Correct |
34 ms |
4216 KB |
Output is correct |
5 |
Correct |
37 ms |
4216 KB |
Output is correct |
6 |
Correct |
77 ms |
7160 KB |
Output is correct |
7 |
Correct |
63 ms |
7288 KB |
Output is correct |
8 |
Correct |
64 ms |
7160 KB |
Output is correct |
9 |
Correct |
65 ms |
7152 KB |
Output is correct |
10 |
Correct |
71 ms |
7160 KB |
Output is correct |
11 |
Correct |
71 ms |
7160 KB |
Output is correct |
12 |
Correct |
74 ms |
7160 KB |
Output is correct |