이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |