이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
bool compare (pair <int, int> a, pair <int, int> b) {
return (a.first <= b.first);
}
signed main () {
int n;
cin >> n;
pair <int, int> arr[n];
for (auto &i : arr) cin >> i.first >> i.second;
sort(arr, arr + n, compare);
int ans = 0;
for (int i = 0; i < n; i++) {
int sum = 0;
int mx = -1e18;
int mn = 1e18;
for (int j = i; j < n; j++) {
mx = max(mx, arr[j].first);
mn = min(mn, arr[j].first);
sum += arr[j].second;
ans = max(ans, sum - (mx - mn));
}
}
cout << ans << endl;
}
# | 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... |