#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define F first
#define S second
#define pii pair<int, int>
#define pic pair<int, char>
#define pci pair<char, int>
#define pipii pair<int, pair<int, int>>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes() cout << "Yes" << endl
#define no() cout << "No" << endl
#define gcd __gcd
int lcm(int a, int b){
return a / gcd(a , b) * b;
}
bool isPalindrome(string s){
string x = s;
reverse(x.begin(), x.end());
return x == s;
}
bool isPrime(int n){
if(n < 2) return false;
if(n == 2) return true;
if(n % 2 == 0) return false;
for(int i = 3;i <= sqrt(n);i += 2){
if(n % i == 0) return false;
}
return true;
}
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
const int MAX = 1e3 + 5;
int dp[MAX][MAX];
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
signed main() {
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int a[n], b[n];
for(int i = 0;i < n;i++){
cin >> a[i] >> b[i];
}
int ans = 0;
for(int mask = 1;mask < (1 << n);mask++){
int sum = 0;
vector<int> vt;
for(int i = 0;i < n;i++){
if(mask & (1 << i)){
sum += b[i];
vt.push_back(a[i]);
}
}
int x = *max_element(vt.begin(), vt.end());
int y = *min_element(vt.begin(), vt.end());
ans = max(ans, sum - (x - y));
}
cout << ans << endl;
}
| # | 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... |