#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << ' ' <<
#define nl << '\n'
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n, ans = 0; cin >> n;
vector<int> a(n+1), b(n+1), c(n+1);
for(int i=1; i<=n; ++i){
cin >> c[i] >> b[i] >> a[i];
ans = max(ans, b[i]);
a[i] += a[i-1];
b[i] += b[i-1];
}
for(int i=0; i<n; ++i) a[i] -= c[i+1];
for(int i=1; i<=n; ++i) a[i] = min(a[i], a[i-1]);
for(int i=1; i<=n; ++i){
int sub = (i < n ? c[i+1] : 0LL);
int low = 0, high = i;
while(low<high){
int mid = (low+high)/2;
if(a[mid] <= a[i] + sub - c[i]) high = mid;
else low = mid+1;
}
ans = max(ans, b[i] - b[low]);
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |