이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h> // PLEASE
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pp;
#define MAXN 500005
#define MAXM 1005
#define MAXP 25
#define A first
#define B second
#define MP make_pair
#define PB push_back
const ll INF = 2e9+13;
const ll MOD = 1e9+7;
int N;
ll sz[MAXN], vl[MAXN];
pp ar[MAXN];
ll p[MAXN];
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N;
for(int i=1; i<=N; i++) cin >> ar[i].A >> ar[i].B;
sort(ar+1, ar+N+1);
for(int i=1; i<=N; i++) {
sz[i] = ar[i].A; vl[i] = ar[i].B;
p[i] = p[i-1] + vl[i];
}
ll mv = sz[1] - p[0];
ll ret = vl[1];
for(int r=1; r<=N; r++) {
mv = max(mv, sz[r] - p[r-1]);
ret = max(ret, p[r] + mv - sz[r]);
}
cout << ret << endl;
}
# | 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... |