#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#define int long long
#define pii pair<int , int>
#define pb push_back
#define all(v) v.begin() , v.end()
#define S second
#define F first
using namespace std;
using namespace __gnu_pbds;
template <typename t>
using indexed_set = tree<t , null_type , less<t> , rb_tree_tag , tree_order_statistics_node_update>;
void Yusiff(){
int n; cin >> n;
vector<pii> v;
int a[n] , b[n];
for(int i = 0; i < n; i++){
cin >> a[i] >> b[i];
v.pb({a[i] , b[i]});
}
sort(a , a + n);
sort(b , b + n);
sort(all(v));
int mnn = v[0].F, mxx = v[0].F;
int sum = v[0].S;
int mx = v[0].S;
for(int i = 1; i < v.size(); i++){
int tempmx = mxx;
int tempmn = mnn;
tempmx = max(tempmx , v[i].F);
tempmn = min(tempmn , v[i].F);
sum = max(v[i].S, sum + v[i].S - (v[i].F - v[i - 1].F));
if(mx < sum){
mxx = tempmx;
mnn = tempmn;
mx = sum;
}
}
cout << mx << '\n';
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while(t--){
Yusiff();
}
}
/*
1 5
4 1
4 2
5 3
9 1
10 3
*/
| # | 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... |