이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main()
{
//freopen("i.txt","r",stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
typedef pair<long long, long long> ii;
ii arr[n];
for(int i = 0;i < n;i++){
cin >> arr[i].first >> arr[i].second;
}
sort(arr,arr+n);
long long pre[n];
pre[0] = arr[0].second;
for(int i = 1;i < n;i++){
pre[i] = pre[i-1] + arr[i].second;
}
long long maxv = 0ll;
long long ans = 0ll;
for(int i = 0;i < n;i++){
ans = max(ans, arr[i].second);
ans = max(pre[i] - arr[i].first + maxv, ans);
long long v = arr[i].first;
if(i != 0) v -= pre[i-1];
maxv = max(maxv, v);
}
cout << ans;
return 0;
}
| # | 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... |