#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
signed main(){
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
vector<pair<ll, ll>> a(n);
for (int i=0; i<n; i++)
cin >> a[i].first >> a[i].second;
sort(a.begin(), a.end());
vector<ll> b(n);
ll pfs = 0;
for (int i=0; i<n; i++)
pfs += a[i].second;
ll max_after = 0, max_val = 0;
for (int i=n-1; i>=0; i--){
max_after = max(max_after, pfs - a[i].first);
pfs -= a[i].second;
// pfs -> pf_(l-1)
max_val = max(max_val, max_after + a[i].first - pfs);
}
cout << max_val << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |