This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define el "\n"
#define pb push_back
#define pp pop_back
#define pii pair <int, int>
#define pll pair <ll, ll>
#define ibase ios_base::sync_with_stdio(0), cin.tie(0);
const int N = 5e5 + 5, M = 1e3 + 5, pw = 31;
const ll MAX = 1e15, inf = 1e9 + 7;
pair <ll, int> p[N];
//ll sum[N];
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i].x >> p[i].y;
}
ll ans = -MAX;
for (int i = 1; i < (1ll << n); i++) {
ll amx = 0, amn = MAX, sum = 0;
for (int j = 0; j < n; j++) {
if (((i >> j) & 1)) {
amx = max(amx, p[j + 1].x);
amn = min(amn, p[j + 1].x);
sum += p[j + 1].y;
}
}
ans = max(ans, sum - (amx - amn));
}
cout << ans;
}
int main() {
ibase;
int T = 1;
// cin >> T;
for (int test = 1; test <= T; ++test) {
// cout << " " << test << ":" << el;
solve();
cout << el;
}
}
# | 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... |