#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test=1,co=0;
for(;test>0;--test)
{
lli n,ans=0;
cin>>n;
lli g[n+1]={},arr[n+1]={},arr1[n+1]={},arr2[n+1]={};
vector<ii> p(n+1);
p[0]=mp(0,0);
for(lli i=1;i<=n;++i)
{
lli y;
cin>>arr1[i]>>g[i]>>y;
p[i].S=i;
p[i].F=p[i-1].F+y-arr1[i]+arr1[i-1];
arr2[i]=arr2[i-1]+y;
g[i]+=g[i-1];
}
sort(p.begin()+1,p.end());
for(lli i=n;i>=1;--i)
{
if(i==n)
arr[i]=p[i].S;
else
arr[i]=max(arr[i+1],p[i].S);
}
for(lli i=1;i<=n;++i)
{
lli a=-(arr1[i]-arr1[1]-arr2[i-1]);
auto it=lower_bound(p.begin()+1,p.end(),mp(a,0*1LL))-p.begin();
if(it!=n+1)
ans=max(ans,g[arr[it]]-g[i-1]);
}
cout<<ans<<endl;
}
return(0);
}
Compilation message
divide.cpp: In function 'int main()':
divide.cpp:21:14: warning: unused variable 'co' [-Wunused-variable]
int test=1,co=0;
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |