답안 #765081

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
765081 2023-06-24T08:17:42 Z Kryz 구경하기 (JOI13_watching) C++17
0 / 100
1 ms 324 KB
#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;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:44:17: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |     for(ll i=1;i<=idx;i++){
      |                ~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 324 KB Output isn't correct
2 Halted 0 ms 0 KB -