이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define en cin.close();return 0;
#define pb push_back
#define fi first//printf("%lli\n",cur);
#define se second//scanf("%lli",&n);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 5e5+5;
ll segt[4*N], lazy[4*N];
int n;
void updlazy(int pos, int siz)
{
if(lazy[pos]!=0)
{
segt[pos]+=lazy[pos];
if(siz!=1)
lazy[pos*2]+=lazy[pos],
lazy[pos*2+1]+=lazy[pos];
lazy[pos]=0;
}
}
void upd(int lb, int rb, ll val, int l = 1, int r = n, int pos = 1)
{
updlazy(pos,r-l+1);
if(rb<l||r<lb)
return;
if(lb<=l&&r<=rb)
lazy[pos]+=val,
updlazy(pos,r-l+1);
else
{
int mid = (l+r)/2;
upd(lb,rb,val,l,mid,pos*2);
upd(lb,rb,val,mid+1,r,pos*2+1);
segt[pos]=max(segt[pos*2],segt[pos*2+1]);
}
}
int main()
{
fio
// ifstream cin("in.in");
cin >> n;
pair<ll,int> p[n+1];
for(int i = 1;i<=n;i++)
cin >> p[i].fi >> p[i].se;
sort(p+1,p+1+n);
p[0]={0,0};
ll res = 0;
for(int i = 1;i<=n;i++)
{
upd(i,i,p[i].se);
upd(1,i-1,-(p[i].fi-p[i-1].fi)+p[i].se);
updlazy(1,n);
res=max(res,segt[1]);
}
cout << res;
// cin.close();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |