이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second
#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using pl = pair<ll, ll>;
ld const PI = 4*atan((ld)1);
int const MAX = 5e5 + 7;
pl art[MAX];
ll pfx[MAX];
int main()
{
fastio;
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> art[i].f1 >> art[i].s2;
sort(art+1, art+1+n);
for (int i = 1; i <= n; ++i)
pfx[i] = pfx[i-1] + art[i].s2;
ll res = 0;
for (int i = 1, j = 1; j <= n; ++j)
{
// using art [i, j]
if (pfx[j-1] - pfx[i-1] < art[j].f1 - art[i].f1)
i = j;
//cerr << i << " " << j << " " << pfx[j] - pfx[i-1] << " " << art[j].f1 << " " << art[j].s2 << '\n';
res = max(res, pfx[j] - pfx[i-1] - (art[j].f1 - art[i].f1));
}
cout << res << '\n';
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... |