#include <bits/stdc++.h>
using namespace std;
#define int long long
#define N 500005
#define f first
#define s second
int tc = 1, n, ans = LLONG_MIN;
pair <int,int> a[N];
void solve(int x,int mx,int mn,int sum) {
if(x == n + 1) {
if(!sum) return;
ans = max(ans,sum-(mx - mn));
return;
}
solve(x + 1, max(mx, a[x].f),min(mn, a[x].f),sum + a[x].s);
solve(x + 1,mx,mn,sum);
}
int32_t main() {
ios::sync_with_stdio(0);cin.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i].f >> a[i].s;
}
solve(1, 0, LLONG_MAX, 0);
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... |