Skip to content

Instantly share code, notes, and snippets.

@estelabn
Created April 9, 2023 20:10
Show Gist options
  • Save estelabn/58b4aad75a71358aabd357841eff845b to your computer and use it in GitHub Desktop.
Save estelabn/58b4aad75a71358aabd357841eff845b to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
map<int,int> m;
vector<pair<int,int> > v;
for(int i=0; i<n; i++){
int x, y; cin >> x >> y;
v.push_back({x,1});
v.push_back({x+y, -1});
}
sort(v.begin(),v.end());
int cont = 0;
vector<int> sum(2*n+1,0);
for(int i=0; i<2*n; i++){// compressão de coordenadas
int x = v[i].first, y = v[i].second;
if(m.find(x) == m.end()){
cont ++;
m[x] = cont;
}
sum[m[x]] += y;
}
int res = 0;
for(int i=1; i<=cont; i++){
sum[i] += sum[i-1];
res = max(sum[i], res);
}
cout << res << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment