#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 500005
typedef long long ll;
using namespace std;
ll n,seg[4*MAXN],lazy[4*MAXN];
pair<ll,ll> niz[MAXN];
ll parc[MAXN];
void dodaj(ll l,ll d,ll tl,ll td,ll k,ll x){
if(lazy[k]){
seg[k]+=(d-l+1)*lazy[k];
if(d!=l){
lazy[k+k]+=lazy[k];
lazy[k+k+1]+=lazy[k];
}
lazy[k]=0;
}
if(l>td || d<tl)return;
if(l>=tl && d<=td){
lazy[k]=x;
seg[k]+=(d-l+1)*lazy[k];
if(d!=l){
lazy[k+k]+=lazy[k];
lazy[k+k+1]+=lazy[k];
}
lazy[k]=0;
return;
}
ll mid=(l+d)/2;
dodaj(l,mid,tl,td,k+k,x);
dodaj(mid+1,d,tl,td,k+k+1,x);
seg[k]=max(seg[k+k],seg[k+k+1]);
}
ll dobij(ll l,ll d,ll tl,ll td,ll k){
if(lazy[k]){
seg[k]+=(d-l+1)*lazy[k];
if(d!=l){
lazy[k+k]+=lazy[k];
lazy[k+k+1]+=lazy[k];
}
lazy[k]=0;
}
if(l>td || d<tl)return 0;
if(l>=tl && d<=td)return seg[k];
ll mid=(l+d)/2;
return min(dobij(l,mid,tl,td,k+k),dobij(mid+1,d,tl,td,k+k+1));
}
int main()
{
scanf("%lld", &n);
for(int i=1;i<=n;i++){
scanf("%lld %lld",&niz[i].first,&niz[i].second);
}
sort(niz+1,niz+n+1);
for(int i =1;i<=n;i++){
parc[i]=parc[i-1]+niz[i].second;
dodaj(1,n,i,i,1,parc[i]-niz[i].first);
}
ll res=0;
for(int i =1;i<=n;i++){
res=max(res,dobij(1,n,i,n,1)+niz[i].first);
dodaj(1,n,i,n,1,-niz[i].second);
}
printf("%lld",res);
return 0;
}
Compilation message
art.cpp: In function 'int main()':
art.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &n);
~~~~~^~~~~~~~~~~~
art.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",&niz[i].first,&niz[i].second);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |