#include "bits/stdc++.h"
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define pb push_back
#define in insert
#define F first
#define S second
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define endl '\n'
#define pii pair<ll,ll>
using namespace std;
const ll INF = 1e18, mod = 1e9 + 7, N = 2e5 + 5;
ll gcd(ll a, ll b){
if(b == 0){
return a;
}
return gcd(b, a%b);
}
ll lcm(ll a, ll b){
return (a / gcd(a,b)) * b;
}
void solve(){
ll n,m;
cin >> n;
vector<pii>v(n);
for(int i = 0; i < n; i++){
cin >> v[i].F >> v[i].S;
}
ll maxi = 0;
ll e;
set<ll>s;
for(int i = 0; i < n; i++){
e=v[i].S;
s.in(v[i].F);
for(int j = 0; j < n; j++){
if(i == j){
continue;
}
// cout << i << endl;
e += v[j].S;
s.in(v[j].F);
auto it = s.end();
it--;
// cout << *it << endl;
auto it1 = s.begin();
// cout << *it1 << endl;
maxi = max(maxi, e - (*it - *it1));
}
s.clear();
}
cout << maxi << endl;
}
int main() {
fast;
ll t = 1;
// cin >> t;
while(t--){
solve();
}
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... |