이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)
int main() {
//freopen("in.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
using pll=pair<ll, ll>;
int n; cin >> n;
pll ab[n+1];
FOR(i,1,n){
ll a, b; cin >> a >> b;
ab[i] = mp(a,b);
}
sort(ab+1, ab+1+n);
ll pre[n+1]; pre[0] = 0;
FOR(i,1,n) pre[i] = pre[i-1] + ab[i].sc;
// max S - (Amax-Amin)
// max pre[i]-pre[j-1] - A[i] + A[j]
ll maxi = 0, ans = 0;
FOR(i,1,n){
maxi = max(maxi, -pre[i-1]+ab[i].fi);
ans = max(ans, pre[i]-ab[i].fi + maxi);
}
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... |