답안 #207749

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
207749 2020-03-08T19:15:03 Z amiratou Art Exhibition (JOI18_art) C++14
0 / 100
5 ms 376 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
//#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int A[500003],B[500003],maxi[500003];
int32_t main(){
	boost;
	//freopen(".in","r",stdin);
	int n,ans=0;
    cin>>n;
    v cum(n,0);
    vii vec(n);
    for (int i = 0; i < n; ++i){
        cin>>A[i]>>B[i],ans=max(ans,B[i]);    
        vec[i]=ii(A[i],B[i]);
    }
    sort(all(vec));
    for (int i = n-1; i >=0 ; i--){
        cum[i]+=vec[i].se;
        if(i!=(n-1))cum[i]+=cum[i+1];
    }
    for (int i = n-1; i >=0 ; i--)
        cum[i]+=vec[i].fi;
    for (int i = 0; i < n; ++i)
    {
        maxi[i]=cum[i];
        if(i)maxi[i]=max(maxi[i],maxi[i-1]);
    }
    for (int i = n-1; i >=1; i--)
        ans=max(ans,maxi[i-1]-vec[i].fi-((i!=(n-1))?(cum[i+1]-vec[i+1].fi):0));
    cout<<ans<<"\n";
	return 0;
}
//long long
//array bounds
//special cases
//binary search
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -