제출 #643499

#제출 시각아이디문제언어결과실행 시간메모리
643499GaLzArt Exhibition (JOI18_art)C++14
100 / 100
213 ms32604 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vll; const ll mod=1e9+7; const ll maxn=5e5+5; const int INF=1e9; #define ok ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define fi first #define se second #define pb push_back #define ub upper_bound #define lb lower_bound #define endl '\n' int n; pll arr[maxn], suf[maxn]; ll cur, sum[maxn], ans; int main() { ok cin >> n; for(int i=1; i<=n; i++) cin >> arr[i].fi >> arr[i].se; sort(arr+1, arr+n+1); for(int i=1; i<=n; i++) { cur+=arr[i].se; suf[i]={cur-(arr[i].fi-arr[1].fi), i}; sum[i]=cur; } for(int i=n-1; i>=1; i--) { if(suf[i].fi<suf[i+1].fi) { suf[i]={suf[i+1].fi, suf[i+1].se}; } } for(int i=1; i<=n; i++) { pll now=suf[i]; ans=max(ans, sum[now.se]-sum[i-1]-(arr[now.se].fi-arr[i].fi)); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...