#include <bits/stdc++.h>
#define int long long
using namespace std;
#define F first
#define S second
#define pb push_back
#define ins insert
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define srt(p) sort(p.begin() , p.end())
#define rvr(p) reverse(p.begin() , p.end())
#define all(p) (p.begin() , p.end())
const int INF = 1e6 , MOD = 1e9 + 7;
bool is_prime(int n) {
if(n == 1 or n == 0) return false;
if(n == 2) return true;
if(n % 2 == 0) return false;
for(int i = 3; i <= sqrt(n); i+=2) {
if(n % i == 0) return false;
}
return true;
}
struct Edge {
int u , v , w;
};
void solve() {
int n;
cin >> n;
vector<pair<int , int>> vt(n);
for(int i = 0; i < n; ++ i) {
cin >> vt[i].F >> vt[i].S;
}
srt(vt);
int maxx = INT_MIN;
for(int l = 0; l < n; ++ l) {
for(int r = l; r < n; ++ r) {
int mini = INT_MAX;
int maxi = INT_MIN;
int cem = 0;
for(int i = l; i <= r; ++ i) {
maxi = max(maxi , vt[i].F);
mini = min(mini , vt[i].F);
cem += vt[i].S;
}
int s = cem - (maxi - mini);
maxx = max(maxx , s);
}
}
cout << maxx << endl;
}
signed main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
//cin >> t;
while (t--) {
solve();
}
}
| # | 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... |