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 <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <map>
#include <set>
#include <complex>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <random>
#define ft first
#define sc second
#define pb push_back
#define len(v) (int)v.size()
#define int ll
using namespace std;
typedef long long ll;
signed main() {
#ifdef PC
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int ans = 0, bal = 0, minn = 0;
map<int, int> zer;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
zer[a] += b;
}
vector<pair<int, int>> have;
for (auto x : zer) {
have.pb(x);
ans = max(ans, x.sc);
}
n = len(have);
have.pb({100, 100});
for (int i = 0; i < n; i++) {
ans = max(ans, bal + have[i].sc - minn);
bal += (have[i].sc - (have[i + 1].ft - have[i].ft));
minn = min(minn, bal);
}
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... |