#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define int long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define Airplane ios::sync_with_stdio(false); cin.tie(nullptr);
const int INF = 1e18;
const int MOD = 1e9 + 7;
int binpow(int b, int e, int mod) {
int res = 1;
while (e > 0) {
if (e % 2 == 1) res = (res * b) % mod;
b = (b * b) % mod;
e /= 2;
}
return res;
}
signed main() {
Airplane
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
vector<pair<int, int>> v;
for (int i = 0; i < n; i++) v.pb({a[i], b[i]});
sort(all(v));
int ans = LLONG_MIN;
for (int i = 0; i < n; i++) {
int sum = 0;
int amin = v[i].first;
for (int j = i; j < n; j++) {
sum += v[j].second;
int amax = v[j].first;
ans = max(ans, sum - (amax - amin));
}
}
cout << ans << "\n";
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... |