#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define int long long
#define ull unsigned long long
#define lb lower_bound
#define ub upper_bound
void solve() {
int n;
cin >> n;
int a[n], b[n];
for (int i = 1; i <= n; i++){
cin >> a[i - 1] >> b[i - 1];
}
int ans = 0;
for (int mask = 0; mask < (1 << n); mask++){
int sum = 0;
int mn = LLONG_MAX;
int mx = LLONG_MIN;
for (int i = 0; i < n; i++){
if((mask & (1 << i))){
mn = min(mn, a[i]);
mx = max(mx, a[i]);
sum += b[i];
}
}
ans = max(ans, sum - (mx - mn));
}
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
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... |