#include <bits/stdc++.h>
using namespace std;
void solve_2_n(vector <pair<long long,long long>> v){
long long best=LLONG_MIN;
long long n=v.size();
for(long long mask=0; mask<(1<<n); mask++){
long long S=0;
long long amin=-1,amax=0;
for(long long i=0;i<n;i++){
if(mask & (1<<i)){
if (amin==-1){amin=v[i].first;}
amin=min(amin,v[i].first);
amax=max(amax,v[i].first);
S+=v[i].second;
}
}
best=max(best,S+amin-amax);
}
cout<<best<<"\n";
}
int main(){
long long n,tm1,tm2;
cin>>n;
vector <pair<long long,long long>> v;
for (long long i=0; i<n; i++){
cin>>tm1>>tm2;
v.push_back({tm1,tm2});
}
solve_2_n(v);
}
| # | 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... |