/*
* * author: attacker
* * created: 08.02.2026 17:56:27
*/
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
#define mt_rng mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
vector<int64_t> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
int64_t ans = -1;
for (int mask = 1; mask < (1 << n); mask++) {
int64_t s = 0, mx = 0, mn = int64_t(1e18);
for (int i = 0; i < n; i++) {
if (mask & (1 << i)) {
mx = max(mx, a[i]);
mn = min(mn, a[i]);
s += b[i];
}
}
ans = max(ans, s - (mx - mn));
}
cout << ans << '\n';
return 0;
}
| # | 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... |