제출 #405687

#제출 시각아이디문제언어결과실행 시간메모리
405687PietraArt Exhibition (JOI18_art)C++14
50 / 100
568 ms19832 KiB
#include<bits/stdc++.h> #define ll long long using namespace std ; const int maxn = 500000 ; const ll inf = 1e18 ; ll n, best, mx, sum[maxn] ; pair<ll, ll> a[maxn] ; int main(){ cin >> n ; for(int i = 1 ; i <= n ; i++) cin >> a[i].first >> a[i].second ; sort(a + 1, a + 1 + n) ; for(int i = 1 ; i <= n ; i++) sum[i] = sum[i-1] + a[i].second ; best = -inf ; for(int i = 1 ; i <= n ; i++){ best = max(best, -sum[i-1] + a[i].first) ; mx = max(mx, sum[i] - a[i].first + best) ; } cout << mx << "\n" ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...