이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
#define el cout << '\n';
using namespace std;
const int N = 5e5+5;
const int inf = 1e18;
const int LG = 31;
const int MOD = 1e9+7;
//const int mod = 998244353;
int n;
pair<int,int> a[N];
int dp[N],pre[N];
pair<int,int> b[N];
bool cmp(pair<int,int> x, pair<int,int> y){
if(x.fi != y.fi) return x.fi < y.fi;
return x.se > y.se;
}
void solve(){
cin>>n;
for(int i=1; i<=n; i++) cin>>a[i].fi >> a[i].se;
sort(a+1,a+1+n,cmp);
for(int i=1; i<=n; i++) pre[i] = pre[i-1] + a[i].se;
int mx=0,ans=0;
for(int i=1; i<=n; i++){
mx = max(mx, a[i].fi - pre[i-1]);
ans = max(ans , mx+pre[i]-a[i].fi);
}
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
el;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |