이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |