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>
using namespace std;
#define ll long long
int main()
{
ll n;
cin>>n;
vector<pair<ll,ll>> a(n);
for(ll i = 0;i < n;i++)cin>>a[i].first>>a[i].second;
sort(a.begin(),a.end());
a.push_back({1e15+1,0});
vector<pair<ll,ll>> v;
for(ll i = 0;i < n;i++)
{
if(a[i].first == a[i+1].first)a[i+1].second += a[i].second;
else v.push_back(a[i]);
}
n = v.size();
ll mx = v[0].second,x = mx,pos = 0;
for(ll i = 1;i < n;i++)
{
x += v[i].second - (v[i].first - v[i-1].first);
if(x >= mx)
{
mx = x;
pos = i;
}
}
ll ans = mx;
for(ll i = 1;i < pos;i++)
{
mx -= v[i-1].second;
mx += v[i].first - v[i-1].first;
ans = max(ans,mx);
}
cout<<max(ans,v[pos].second);
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... |