This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = 5e5 + 10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long n;
vector < pair < long long , long long > > g;
long long a[MAXN], b[MAXN];
long long p[MAXN];
void read()
{
cin >> n;
g.push_back(make_pair(-1, -1));
for (long long i = 1; i <= n; ++ i)
cin >> a[i] >> b[i];
for (long long i = 1; i <= n; ++ i)
{
g.push_back(make_pair(a[i], b[i]));
}
sort(g.begin(), g.end());
for (long long i = 1; i <= n; ++ i)
{
p[i] = p[i-1] + g[i].second;
}
}
void solve()
{
priority_queue < long long > q;
long long ans = 0, cost = 0;
for (int i = 1; i <= n; ++ i)
{
q.push(g[i].first - p[i-1]);
cost = q.top() + p[i] - g[i].first;
ans = max(cost, ans);
}
cout << ans << endl;
}
int main()
{
speed();
read();
solve();
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... |