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