/**
III U U N N DDDD EEEEE RRRR SSSS TTTTT AAAAA N N DDDD I TTTTT N N OOO W W
I U U NN N D D E R R S T A A NN N D D I T NN N O O W W
I U U N N N D D EEEE RRRR SSSS T AAAAA N N N D D I T N N N O O W W W
I U U N NN D D E R R S T A A N NN D D I T N NN O O WW WW
III UUUUU N N DDDD EEEEE R R SSSS T A A N N DDDD I T N N OOO W W
**/
//18.09.25
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define ent '\n'
#define F first
#define S second
#define in insert
#define no "NO\n"
#define yes "YES\n"
#define pb push_back
#define sz(w) w.size()
#define int long long
#define pii pair <int, int>
#define all(w) w.begin(), w.end()
#define rall(w) w.rbegin(), w.rend()
#define BakTR ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int MOD = 998244353, N = 2e5 + 7 , inf = 1e9 + 7, INF = 2e18, LOG = 20 , mod = 1e9 + 7 , block = 300 ;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// template <typename T>
// using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
void accepted() {
int n ;
cin >> n ;
pii p[n + 1] ;
for(int i = 1 ; i <= n; i ++) {
cin >> p[i].F >> p[i].S ;
}
sort(p + 1, p +n + 1) ;
int mx = 0 ;
for(int l = 1 ; l < n ; l++) {
int sum = p[l].S ;
for(int r = l + 1 ; r <= n ; r++) {
sum += p[r].S ;
int ans = sum - abs(p[r].F - p[l].F) ;
mx = max(mx , ans) ;
}
}
cout << mx ;
}
signed main() {
BakTR
//PLS NeverGiveUp
// freopen("sum2.in", "r", stdin) ;
// freopen("sum2.out", "w", stdout) ;
int T = 1 ;
// cin >> T ;
while (T--) {
accepted() ;
cout << ent ;
}
}
/**
baktr
**/
# | 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... |