#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
vector<pair<ll, ll>> p(1, {0, 0});
vector<ll> psum(n + 1, 0);
map<ll, ll> mp;
for (int i = 1; i <= n; i++) {
ll a, b; cin >> a >> b;
mp[a] += b;
}
for (auto [a, b] : mp) {
p.push_back({a, b});
}
n = p.size() - 1;
for (int i = 1; i <= n; i++) {
psum[i] = p[i].second + psum[i - 1];
}
ll ans = 0;
for (int i = 1, l = 1; i <= n; i++) {
ll cur = psum[i] - psum[l - 1] - (p[i].first - p[l].first);
ans = max(ans, cur);
if (psum[i - 1] - psum[l - 1] < p[i].first - p[l].first) {
l = i;
ans = max(ans, psum[i] - psum[i - 1]);
}
}
cout << ans << '\n';
}
| # | 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... |