This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
pair<ll,ll> wej[500003];
ll sum_pref[500003];
ll next_min[500003];
ll dp[500003][2];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n,mx=0;
cin >> n;
for (ll i = 1; i<=n; i++){
cin >> wej[i].first >> wej[i].second;
}
sort(wej+1,wej+n+1);
for (ll i = 1; i<=n; i++){
dp[i][0]=wej[i].first+wej[i].second;
dp[i][1]=max(dp[i-1][0],dp[i-1][1])+wej[i].second;
mx=max({mx,dp[i][0]-wej[i].first,dp[i][1]-wej[i].first});
}
cout << mx << '\n';
}
# | 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... |