#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
#define int long long
const int N = 5e5 + 10;
ll suf_max[N];
void solve()
{
int n;
cin >> n;
vector<pair<int,int>> a(n);
vector<int> pref(n);
for(int i = 0;i < n; ++i){
cin >> a[i].first >> a[i].second;
}
sort(all(a));
for(int i = 0;i < n; ++i){
pref[i] = a[i].second;
if(i)pref[i] += pref[i - 1];
}
for(int i = n - 1;i >= 0; --i){
suf_max[i] = max(suf_max[i + 1], pref[i] - a[i].first);
}
ll ans = 0;
for(int i = 0;i < n; ++i){
ans = max(ans, a[i].second);
if(i + 1 < n){
ans = max(ans, suf_max[i] - pref[i] + a[i].second + a[i].first);
}
}
cout << ans << "\n";
}
int32_t main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while(t--)
{
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |