이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* author: Perl32
* created: 07.09.2023 21:10:21
**/
#ifdef LOCAL
# define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ff first
#define ss second
#define szof(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#ifndef LOCAL
# define cerr __get_ce__
#endif
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
using namespace __gnu_pbds;
template<typename K, typename V> using normal_unordered_map = gp_hash_table<K, V>;
template<typename T> using normal_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
const ll INF = (ll) 1e9 + 1e3;
const ll INFL = (ll) 1e18 + 1e9;
#ifdef LOCAL
mt19937 tw(9450189);
#else
mt19937 tw(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
uniform_int_distribution<ll> ll_distr;
ll rnd(ll a, ll b) { return ll_distr(tw) % (b - a + 1) + a; }
signed main() {
#ifdef LOCAL
freopen("inp.txt", "r", stdin);
freopen("out.txt", "w", stdout);
freopen("err.txt", "w", stderr);
auto start_time = clock();
cerr << setprecision(3) << fixed;
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<pll> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i].ff >> a[i].ss;
}
sort(all(a));
vector<ll> pref(n + 1);
for (int i = 0; i < n; ++i) {
pref[i + 1] = pref[i] + a[i].ss;
}
ll ans = a[0].ss, mx = a[0].ff;
for (int i = 1; i < n; ++i) {
ans = max(ans, pref[i + 1] - a[i].ff + mx);
mx = max(mx, a[i].ff - pref[i]);
}
cout << ans;
#ifdef LOCAL
auto end_time = clock();
cerr << "Execution time: " << (end_time - start_time) * (ll) 1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}
# | 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... |