/// dwuy: _,\,,,_\,__,\,,_
#include <bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define file(a) freopen(a".inp","r",stdin); freopen(a".out", "w",stdout)
#define fi first
#define se second
#define endl "\n"
#define len(s) int32_t(s.length())
#define MASK(k)(1LL<<(k))
#define TASK ""
#define int long long
using namespace std;
typedef tuple<int, int, int> tpiii;
typedef pair<double, double> pdd;
typedef pair<int, int> pii;
typedef long long ll;
const long long OO = 1e18;
const int MOD = 1e9 + 7;
const int INF = 1e9;
struct SMT{
int n;
vector<int> tree;
SMT(int n=0){
this->n = n;
this->tree.assign(n<<2|1, OO);
}
void update(int pos, int val){
int id = 1;
for(int lo=1, hi=n; lo<hi;){
int mid = (lo+hi)>>1;
if(pos<=mid) hi = mid, id = id<<1;
else id = id<<1|1, lo = mid + 1;
}
tree[id] = min(tree[id], val);
for(id>>=1; id; id>>=1) tree[id] = min(tree[id<<1], tree[id<<1|1]);
}
int get(int l, int r, int id, const int &u, const int &v){
if(l>v || r<u) return OO;
if(l>=u && r<=v) return tree[id];
int mid = (l+r)>>1;
return min(get(l, mid, id<<1, u, v), get(mid+1, r, id<<1|1, u, v));
}
int get(int l, int r){
if(l>r) return OO;
return get(1, n, 1, l, r);
}
};
const int MX = 100005;
int n;
int p[MX];
int g[MX];
int e[MX];
int pfg[MX];
int pfe[MX];
void nhap(){
cin >> n;
for(int i=1 ; i<=n; i++){
cin >> p[i] >> g[i] >> e[i];
pfg[i] = pfg[i-1] + g[i];
pfe[i] = pfe[i-1] + e[i];
}
}
void solve(){
vector<int> rv;
for(int i=1; i<=n; i++) rv.push_back(p[i] - pfe[i-1]);
sort(rv.begin(), rv.end());
rv.erase(unique(rv.begin(), rv.end()), rv.end());
SMT smt(rv.size());
int ans = 0;
for(int i=1; i<=n; i++){
int pos = lower_bound(rv.begin(), rv.end(), p[i] - pfe[i-1]) - rv.begin() + 1;
smt.update(pos, pfg[i-1]);
pos = lower_bound(rv.begin(), rv.end(), p[i] - pfe[i]) - rv.begin() + 1;
ans = max(ans, pfg[i] - smt.get(pos, rv.size()));
}
cout << ans;
}
int32_t main(){
fastIO;
//file(TASK);
nhap();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2508 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2508 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2524 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
2 ms |
2652 KB |
Output is correct |
23 |
Correct |
3 ms |
2908 KB |
Output is correct |
24 |
Correct |
3 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2508 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2652 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2524 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
2 ms |
2652 KB |
Output is correct |
23 |
Correct |
3 ms |
2908 KB |
Output is correct |
24 |
Correct |
3 ms |
2908 KB |
Output is correct |
25 |
Correct |
2 ms |
2908 KB |
Output is correct |
26 |
Correct |
4 ms |
3188 KB |
Output is correct |
27 |
Correct |
5 ms |
3420 KB |
Output is correct |
28 |
Correct |
22 ms |
6364 KB |
Output is correct |
29 |
Correct |
24 ms |
6876 KB |
Output is correct |
30 |
Correct |
48 ms |
11216 KB |
Output is correct |
31 |
Correct |
45 ms |
10148 KB |
Output is correct |
32 |
Correct |
45 ms |
10196 KB |
Output is correct |
33 |
Correct |
44 ms |
9936 KB |
Output is correct |
34 |
Correct |
42 ms |
9936 KB |
Output is correct |
35 |
Correct |
44 ms |
10456 KB |
Output is correct |
36 |
Correct |
45 ms |
10704 KB |
Output is correct |