이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define sst string
#define pb push_back
#define maxco 100000+5
#define lld long double
#define cha ios_base::sync_with_stdio(false);
#define ffl cout.flush();
#define phi acos(-1)
#define mod 707
#define mr make_pair
#define pqin priority_queue<ll,vector<ll>,greater<>>
#define pqpair priority_queue<pair<ll,ll> ,vector<pair<ll,ll>>,greater<pair<ll,ll>>>
#define pqpair2 priority_queue<pair<pair<ll,ll>,pair<ll,ll>>,vector<pair<pi,pair<ll,ll>>>,greater<pair<pi,pair<ll,ll>>>>
#define INF 1000000009
#define MAXN 500069
#define pi pair<ll,ll>
ll mvx[]={1,-1,0,0};
ll mvy[]={0,0,1,-1};
pair<ll,ll> pr[MAXN];
ll ps[MAXN];
int main(){
ll n;
cin>>n;
set<ll> st;
for(ll i=1;i<=n;i++){
cin>>pr[i].fi>>pr[i].se;
}
sort(pr+1,pr+n+1);
ll mk=0;
ll idx;
for(ll i=1;i<=n;i++){
ps[i]+=ps[i-1]+pr[i].se;
if(ps[i]-pr[i].fi>mk){
mk=ps[i]-pr[i].fi;
idx=i;
}
}
ll ans=0;
for(ll i=1;i<=idx;i++){
ans=max(ans,pr[i].fi+ps[idx]-ps[i-1]-pr[idx].fi);
}
for(ll i=1;i<=n;i++){
ans=max(ans,pr[i].se-pr[i].fi);
}
cout<<ans<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
art.cpp: In function 'int main()':
art.cpp:44:17: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
44 | for(ll i=1;i<=idx;i++){
| ~^~~~~
# | 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... |