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>
typedef long long ll;
using namespace std;
const ll maxN = 5e5+10;
vector<pair<ll, ll>> a;
map<ll, ll> b;
ll n;
int main()
{
ios_base::sync_with_stdio(0);cin.tie(nullptr);
cin>>n;
for(int i = 0; i < n; i++){
ll aa, bb;
cin>>aa>>bb;
a.push_back({aa, bb});
}
for(int i = 0; i < n; i++){
b[a[i].first]+=a[i].second;
}
a.clear();
for(auto i : b){
a.push_back({i.first, i.second});
}
sort(a.begin(), a.end());
n = a.size();
ll i = 0, j = 0;
ll s=a[0].second;
ll mx=0;
while(j<n-1){
//cout<<s<<" "<<i<<" "<<j<<" "<<abs(a[j].first-a[i].first)<<endl;
mx=max(mx, s-abs(a[j].first-a[i].first));
if(i!=j&&a[i+1].first-a[i].first>=a[i].second){
s-=a[i].second;
i++;
continue;
}
j++;
s+=a[j].second;
}
while(i<n){
mx=max(mx, s-abs(a[j].first-a[i].first));
s-=a[i].second;
i++;
}
mx=max(mx, s-abs(a[j].first-a[i].first));
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... |