#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using ll = long long;
#define pb push_back
#define F first
#define S second
#define vii vector<int>
#define vl vector<long long>
#define cinv(v) for (auto &it : v) cin >> it;
#define coutv(v) for (auto &it : v) cout << it << " "; cout << '\n';
#define dbg_var(x,y) cout<<y<<"# Debugging: "<<x<<'\n';
using namespace std;
//using namespace __gnu_pbds;
//template<class T> using ordset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void solve()
{
int n;
cin>>n;
vector<pair<ll,ll>> v(n);
for(int i=0;i<n;++i)
cin>>v[i].F>>v[i].S;
ll ans = LLONG_MIN;
for(int i=1;i<=(1 << n);++i)
{
ll s = 0;
ll a1 = LLONG_MIN;
ll a2 = LLONG_MAX;
for(int j=0;j<n;++j)
{
if(i & (1 << j))
{
s+=v[j].S;
a1 = max(v[j].F,a1);
a2 = min(v[j].F,a2);
}
}
ans = max(s - (a1 - a2), ans);
}
cout<<ans<<'\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
//int t;cin>>t;while(t--)
solve();
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... |