이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define ll long long
#define For(i,a,b) for(ll i=(a);i<=(b);i++)
#define Ford(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define endl "\n"
using namespace std;
int Dx[] = {0, 1, 0, -1, -1, -1, 1, 1};
int Dy[] = {-1, 0, 1, 0, 1, -1, 1, -1};
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
const ll inf = 1000000000000000000;
const int N = 100000;
const int block_size = 300;
const ll MOD = 1e9 + 7; /* 998244353 */
const int LG = 18;
const int K = 20;
const int M = 100000;
ll nph(ll k, ll x) { return ((x >> k) & 1LL); }
void Solve() {
ll n; cin>>n; pair<ll, ll> a[n+3];
For(i, 1, n) cin>>a[i].fi>>a[i].se;
sort(a+1, a+n+1);
ll pre[n+3]; pre[0] = 0;
For(i, 1, n) pre[i] = pre[i-1] + a[i].se;
ll mn = 0, ans = 0;
For(i, 1, n) {
ans = max(ans, pre[i] - a[i].fi - mn);
mn = min(mn, pre[i-1] - a[i].fi);
}
cout << ans;
}
int main() {
// freopen("PHOTO.INP", "r", stdin);
// freopen("PHOTO.OUT", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
//cin >> t;
while(t--)
Solve();
}
| # | 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... |