이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define endl '\n'
#define fr first
#define sc second
#define all(v) v.begin(),v.end()
#define unq(v) sort( all(v) ); v.erase( unique( all(v) ), v.end() )
#define bout(x) cout << bitset<sizeof(x)*8>(x) << endl
#define mkp(a,b) make_pair(a,b)
#define gcd(a,b) __gcd(a,b)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using cpl = complex<ld>;
const ld pi = 3.14159265358979323846264338327950288;
const ld tau = 2 * pi;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, ddy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int nx[8] = {1, 2, 2, 1, -1, -2, -2, -1}, ny[8] = {-2, -1, 1, 2, 2, 1, -1, -2};
//#define DEBUG
pll arr[500020];
ll prf[500020];
ll res[500020];
ll mx[500020];
void Main(){
int n; cin >> n;
for (int i = 1; i <= n; i++){
cin >> arr[i].fr >> arr[i].sc;
}
sort(arr+1, arr+n+1, [](pll a, pll b){
return a.fr < b.fr;
});
for (int i = 1; i <= n; i++){ prf[i] = prf[i-1] + arr[i].sc; }
for (int i = 1; i <= n; i++){ res[i] = prf[i] - arr[i].fr; }
mx[n] = res[n];
for (int i = n; i >= 1; i--){ mx[i] = max(mx[i+1], res[i]); }
ll ans = 0;
for (int i = 1; i <= n; i++){
ans = max(ans, mx[i] - res[i] + arr[i].sc);
}
cout << ans;
}
int main(){
#ifndef DEBUG
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#endif
cout.setf(ios::fixed);
cout.precision(0);
Main();
}
# | 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... |