제출 #988160

#제출 시각아이디문제언어결과실행 시간메모리
988160MuhammetArt Exhibition (JOI18_art)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define N 500005 #define ll long long int #define sz(x) (int)x.size() #define ff first #define ss second ll T, n, f[N], mx[N]; pair <ll,ll> a[N]; int main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> n; ll s = 0; for(int i = 1; i <= n; i++){ cin >> a[i].ff >> a[i].ss; s += a[i].ss; } sort(a+1,a+n+1); for(int i = n; i >= 1; i--){ f[i] = f[i+1] - a[i].ss; mx[i] = max(mx[i+1], f[i] + (a[n].ff - a[i-1].ff)); } ll ans = mx[1], x = 0; for(int i = 1; i <= n; i++){ x += a[i].ss; ans = max(ans,mx[i+1] + a[i].ff - x); } ans += (s - (a[n].ff - a[1].ff)); cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...