#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(x) cout << (#x) << " is " << (x) << '\n'
#else
#define debug(x) 42
#endif
#define int long long
const int maxN = (int)1e6;
int t= 0,n;
unordered_map<int,int>compress;
class Fenwick{
public:
int tree[maxN];
void init(){
for (int i = 0 ; i < maxN; i++)tree[i] = (int)1e9;
}
void update(int pos, int val){
while(pos <= t){
tree[pos] = min(tree[pos], val);
pos += pos & (-pos);
}
}
int get(int pos){
int ans = (int)1e9;
while(pos){
ans = min(ans, tree[pos]);
pos -= pos & (-pos);
}
return ans;
}
};
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
vector<vector<int>>a(n,vector<int>(3));
for (int i = 0; i < n; i++){
cin >> a[i][0] >> a[i][1] >> a[i][2];
}
sort(a.begin(), a.end());
int len = 0, energy = 0;
vector<int>b;
b.push_back(0);
for (int i = 0; i < n; i++){
len += a[i][0];
if (i)len-=a[i-1][0];
energy += a[i][2];//Cr - Cl <= Er - El, Cr - Er <= Cl - El
b.push_back(len - energy);
}
sort(b.rbegin(), b.rend());
for (int i = 0; i < (int)b.size(); i++){
if (!i || b[i] != b[i - 1])compress[b[i]] = ++t;
}
len = 0, energy = 0;
int ans = 0;
Fenwick tr;
tr.init();
int ps[n + 1];
memset(ps, 0LL, sizeof(ps));
for (int i = 0; i < n; i++){
int prev = len - energy;
len += a[i][0];
if (i)len-=a[i-1][0];
energy += a[i][2];
ps[i + 1] += a[i][1] + ps[i];
int ask = tr.get(compress[len - energy]);
int res = ps[i+1] - (ask != (int)1e9 ? ps[ask - 1] : ps[i]);
tr.update(compress[prev], i+1);
ans = max(ans, res);
}
cout<<ans<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8148 KB |
Output is correct |
2 |
Incorrect |
6 ms |
8020 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8148 KB |
Output is correct |
2 |
Incorrect |
6 ms |
8020 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
8148 KB |
Output is correct |
2 |
Incorrect |
6 ms |
8020 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |