#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
#define Bismillah ios_base::sync_with_stdio(0);cin.tie(0);
#define indexed_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
const int N = 5e5 + 7;
const int INF = 1e18;
const int MOD = 998244353;
int n , a[N] , b[N];
signed main()
{
Bismillah;
// freopen("closing.in", "r", stdin);
// freopen("closing.out", "w", stdout);
cin >> n;
for(int i = 0; i < n; i++)
{
cin >> a[i] >> b[i];
}
int res = -1;
for(int bit = 1; bit < (1 << n); bit++)
{
int sum = 0, mx = -1 , mn = INF;
for(int i = 0; i < n; i++)
{
if(bit & (1 << i))
{
sum += b[i];
mx = max(mx , a[i]);
mn = min(mn , a[i]);
}
}
res = max(res , (sum - (mx - mn)));
}
cout << res << 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... |