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 <bits/stdc++.h>
//#include <bits/extc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
//using namespace __gnu_pbds;
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ull = unsigned ll;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x first
#define y second
#define ll long double
//const int MOD = 1e9 + 7;
const int MOD = 998244353;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
const char dir[] = {'R', 'L', 'D', 'U'};
/*
int add(int a, int b){ //(a + b) % 1e9 + 7
a += b;
if(a < 0){
a += MOD;
}
if(a >= MOD){
a -= MOD;
}
return a;
}
int sub(int a, int b){
a -= b;
if(a < 0) a += MOD;
return a;
}
int mult(int a, int b){
return ((ll) a * b) % MOD;
}*/
void setIO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen((s+".in").c_str(),"r",stdin);
// freopen((s+".text").c_str(),"w",stdout);
}
signed main(){
setIO();
//CHECK FOR LONG LONG!!!
//LONG LONG OVERFLOW??
int n; cin >> n;
pll art[n];
ll pref[n + 1];
fill(pref, pref + n + 1, 0);
for(int i = 0; i < n; ++i){
cin >> art[i].x >> art[i].y;
}
sort(art, art + n);
for(int i = 0; i < n; ++i){
pref[i + 1] = pref[i] + art[i].y;
}
ll ans = art[n - 1].y;
set<ll> poss;
poss.insert(pref[n] - art[n - 1].x);
for(int i = n - 2; i >= 0; --i){
ans = max(ans, *prev(poss.end()) - pref[i] + art[i].x);
poss.insert(pref[i + 1] - art[i].x);
}
cout << (long long) ans << "\n";
//CHECK FOR LONG LONG!!!
}
# | 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... |