답안 #1050016

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1050016 2024-08-09T06:53:44 Z vjudge1 Art Exhibition (JOI18_art) C++17
0 / 100
1 ms 2396 KB
#include <bits/stdc++.h>
using namespace std;

//typedef long long ll;
///typedef unsigned long long ull;
//typedef pair<long long,long long> pl;

#define all(s) s.begin(),s.end()
#define F first
#define S second
#define sz(a) a.size()
#define int long long

typedef pair<int,int> pi;

//const ll mod = 998244353;
//const ll mod1 = 1e9+7;
//const ll INF = 1e18;
const int N = 100200;
const int inf = 1e18+200;



int n;
pi a[N*5];
int p[N*5];
pi b[N*5];

void solve() {
    cin>>n;
    for(int i=1;i<=n;++i) {
        cin>>a[i].F>>a[i].S;
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=n;++i) {
        p[i]=p[i-1]+a[i].S;
    }
    int mn=-inf;
    int mx=-inf;
    int ans=0;
    int mxi;
    int mni;
    
    for(int i=1;i<=n;++i) {
        b[i].F=p[i]-a[i].F;
        b[i].S=a[i].F-p[i-1];
    }
    for(int i=1;i<=n;++i) {
        if(mx<=b[i].F) {
            mx=b[i].F;
            mxi=i;
        }
    }
    for(int i=1;i<=n;++i) {
        if(mn<=b[i].S) {
            mn=b[i].S;
            mni=i;
        }
    }
    if(mx>=mn) {
        for(int i=1;i<=mxi;++i) {
            mn=max(mn,b[i].S);
        }
        cout<<mx+mn;
    }
    else {
        for(int i=mni;i<=n;++i) {
            mx=max(mx,b[i].F);
        }
        cout<<mx+mn;
    }
}

signed main() {
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int T=1;
    //cin>>T;
    while(T--) {
        solve();
    }
    return 0;
} 

Compilation message

art.cpp: In function 'void solve()':
art.cpp:40:9: warning: unused variable 'ans' [-Wunused-variable]
   40 |     int ans=0;
      |         ^~~
art.cpp:41:9: warning: 'mxi' may be used uninitialized in this function [-Wmaybe-uninitialized]
   41 |     int mxi;
      |         ^~~
art.cpp:42:9: warning: 'mni' may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |     int mni;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -