제출 #966901

#제출 시각아이디문제언어결과실행 시간메모리
966901vjudge1Art Exhibition (JOI18_art)C++17
100 / 100
152 ms24936 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define pii pair <int, int> #define pb push_back #define mp make_pair #define dbg puts("dbg"); #define outp(x) cout << #x << " = " << (x) << endl #define all(x) (x).begin(), (x).end() #define test int t; cin >> t; while(t--){solve();} #define MOD 998244353 int fpb(int a,int b){if(b == 0){return a;}return fpb(b, a%b);} int kpk(int a,int b){return (a*b)/fpb(a, b);} int n, pref[500003]; pii art[500003]; // i ... j // psum[j] - psum[i-1] - a[j] + a[i] // psum[j] - a[j] + a[i] - psum[i-1] void solve(){ cin >> n; for(int i=1; i<=n; i++){ cin >> art[i].first >> art[i].second; } sort(art+1, art+n+1); for(int i=1; i<=n; i++){ pref[i] = pref[i-1] + art[i].second; } int maxi = -2e18, ans = 0; for(int i=1; i<=n; i++){ maxi = max(maxi, art[i].first - pref[i-1]); ans = max(ans, maxi + pref[i] - art[i].first); } cout << ans << endl; } int32_t main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); solve(); 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...