#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
/**zagaro & lauren <3**/
#define mod 1000000007 //1e9 + 7
#define pi acos(-1)
#define wl while
#define str string
#define ENDL "\n"
#define sal ' '
#define tp_set ll
#define prc(n) cout.precision(n);cout<<fixed;
#define ord_set tree<tp_set, null_type, less<tp_set>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef bool bl;
typedef char car;
using namespace std;
using namespace __gnu_pbds;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll n, r=0, a, b;
cin>>n;
vector<pair<ll,ll> > vec(1, {0, 0});
vector<ll> val;
map<ll,ll> mp;
for(int i=1;i<=n;i++){
cin>>a>>b;
if(mp[a] == 0)val.push_back(a);
mp[a]+=b;
}
for(int i=0;i<val.size();i++)vec.push_back({val[i], mp[val[i]]});
a=0;
sort(vec.begin(), vec.end());
vec[0].first = vec[1].first;
for(int i=1;i<vec.size();i++){
if(a + (vec[i].second)-(vec[i].first-vec[i-1].first) > vec[i].second)a += (vec[i].second)-(vec[i].first-vec[i-1].first);
else a = vec[i].second;
r = max(r, max(a, vec[i].second));
}
cout<<r<<ENDL;
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... |