#include <bits/stdc++.h>
using namespace std;
#define int long long
#define run ios_base::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second
#define endl '\n'
const int inf = 1e18+7;
const int sz = 1e5+5;
void solve() {
int n;
cin >> n;
int a[n+1],b[n+1];
for(int i = 0; i < n;i++) cin >> a[i] >> b[i];
int cost = 0, best = -inf;
for(int bt = 1; bt < 1 << n;bt++){
cost = 0;
int mx = -inf, mn = inf;
for(int i = 0; i < n;i++){
if(bt & (1 << i)){
cost+= b[i];
mx = max(a[i],mx);
mn = min(a[i],mn);
}
}
cost = cost - (mx - mn);
if(cost > best) best = cost;
}
cout << best << endl;
}
signed main() {
run;
int t = 1;
//cin >> t;
while (t--) {
solve();
}
}
// 11111100000
# | 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... |