이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18 + 12;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<pair<ll, ll>> temp(n);
for(auto &z : temp) cin >> z.first >> z.second;
sort(temp.begin(), temp.end());
vector<pair<ll, ll>> v;
ll suma = 0;
v.push_back({0, suma});
for(int i = 0, j = 0; i < n; i = j) {
ll trenutno = 0;
while(j < n && temp[i].first == temp[j].first) {
trenutno += temp[j].second;
++j;
}
suma += trenutno;
v.push_back({temp[i].first, suma});
}
ll ans = 0;
n = int(v.size());
//(pref[r] - pref[l-1]) - a[r] + a[l];
//pref[r] - a[r] + (a[l] - pref[l-1])
// for(auto &[a, b] : v) {
// cout << a << " " << b << endl;
// }
ll maksi = -INF;
for(int i = 1; i < n; ++i) {
maksi = max(maksi, v[i].first - v[i-1].second);
ll tren = v[i].second - v[i].first;
ans = max(ans, maksi + tren);
}
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... |