#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));
if(i!=j&&a[i+1].first-a[i].first>=a[i].second){
s-=a[i].second;
i++;
continue;
}else break;
}
mx=max(mx, s-abs(a[j].first-a[i].first));
cout<<mx;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |