Submission #1049957

# Submission time Handle Problem Language Result Execution time Memory
1049957 2024-08-09T06:21:57 Z vjudge1 Art Exhibition (JOI18_art) C++17
0 / 100
1 ms 2392 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];

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;
    for(int i=1;i<=n;++i) {
        if(mx<=p[i]-a[i].F) {
            mx=max(mx,p[i]-a[i].F);
            mxi=i;
        }
    }
    for(int i=1;i<mxi;++i) {
        mn=max(mn,a[i].F-p[i-1]);
    }
    cout<<mx+mn<<'\n';
}

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:39:9: warning: unused variable 'ans' [-Wunused-variable]
   39 |     int ans=0;
      |         ^~~
art.cpp:40:9: warning: 'mxi' may be used uninitialized in this function [-Wmaybe-uninitialized]
   40 |     int mxi;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -