This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
**/
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 5e5 + 10;
struct element
{
ll v, s;
bool operator < (const element &e) const
{
return s < e.s;
}
}e[maxn];
int n;
void solve()
{
cin >> n;
for (int i = 1; i <= n; i ++)
{
cin >> e[i].s >> e[i].v;
}
sort(e + 1, e + n + 1);
ll p = 0, b = -1e18, ans = 0;
for (int i = 1; i <= n; i ++)
{
b = max(b, - p + e[i].s);
p = p + e[i].v;
ans = max(ans, p - e[i].s + b);
///cout << b << " " << i << endl;
}
cout << ans << endl;
}
int main()
{
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... |