#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define f first
#define s second
#define pb push_back
#define yes cout << "yes" << endl;
#define YES cout << "YES" << endl;
#define no cout << "no" << endl;
#define NO cout << "NO" << endl;
void never_give_up() {
int n;
cin >> n;
vector<int>a(n + 1);
vector<int>b(n + 1);
vector<pair<int, int>>h;
for(int i = 1;i <= n; i++){
//cin >> a[i] >> b[i];
int c ,d;
cin >> c >> d;
h.pb({c, d});
}
sort(h.begin(), h.end());
for(int i = 0;i < n; i++){
//cin >> a[i] >> b[i];
a[i + 1] = h[i].f;
b[i + 1] = h[i].s;
}
/*for(int i = 1;i <= n; i++){
cout << a[i] << " ";
}
cout << endl;
for(int i = 1;i <= n; i++){
cout << b[i] << " ";
}
cout << endl;*/
int cvb = LLONG_MIN;
for(int i = 1; i < n;i ++){
for(int j = i; j <= n; j++){
///////////////////////////
int say = 0;
int mini = LLONG_MAX;
int maxa = LLONG_MIN;
int mi = min(a[i], a[j]);
int ma = max(a[i], a[j]);
//cout << i << " ---- " << j << " <------ " << endl;
for(int k = 1; k <= n; k++){
if(a[k] >= mi && a[k] <= ma){
say += b[k];
mini = min(mini, a[k]);
maxa = max(maxa, a[k]);
//cout << a[i] << " " << b[i] << endl;
}
else if(a[k] > ma){
break;
}
}
//cout << i << " : " << j << endl;
//cout << say << " " << mini << " " << maxa << endl;
cvb = max(cvb, (say - (maxa - mini)));
//cout << cvb << endl;
///////////////////////////
}
}
cout << cvb << endl;
}
void You_can_do_it() {
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int THE_wasd = 1;
//cin >> THE_wasd;
while(THE_wasd--){
never_give_up();
//You_can_do_it();
}
}
| # | 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... |