#include <bits/stdc++.h>
using namespace std;
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#define pb push_back
#define ll long long
#define int long long
//#define sort(all(v)) sort(v.begin(),v.end())
int mod = 998244353;
const int N = 4e5 + 10;
const int inf = 1e9;
int fact[200001];
ll binpow(ll a, ll b){
if(b == 0) return 1;
else if(b % 2 == 1) return (a * binpow(a, b - 1)) % mod;
ll p = binpow(a,b / 2);
return (p * p) % mod;
}
int p[N];
signed main(){
//freopen("mootube.in", "r", stdin);
//freopen("mootube.out", "w", stdout);
int n;
cin >> n;
int a[n + 1],b[n + 1];
for(int i = 1; i <= n; i++){
cin >> a[i] >> b[i];
}
int ans = 0;
for(int mask = 0; mask < (1 << n); mask++){
if(mask == 0) continue;
int s = 0,mx = 0,mn = 1e18;
for(int i = 0; i < n; i++){
if((mask >> i & 1) == 1){
s += b[i + 1];
mx = max(a[i + 1],mx);
mn = min(a[i + 1],mn);
}
}
ans = max(ans,s - (mx - mn));
}
cout << ans;
}
# | 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... |