#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
using namespace std;
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define vc vector
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ll long long
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define int ll
const int N = 5e5 + 5;
const int M = 5e5 + 5;
const int mod = 1e9 + 7;
const int block = 500;
int n;
ll a[N], b[N], pref[N];
void solve() {
cin >> n;
vc <pair<ll,ll>> save;
for ( int i = 1; i <= n; i++ ) {
cin >> a[i] >> b[i];
save.pb(mp(a[i],b[i]));
}
sort(all(save));
ll ans = save[0].se + save[0].fi;
ll res = save[0].se;
int l = 1;
for ( int i = 2; i <= n; i++ ) {
ans += save[i-1].se;
if ( l != i - 1 ) {
ll sum = save[i-1].se + save[i-2].se + save[i-2].fi;
if ( sum > ans ) {
ans = sum;
l = i - 1;
}
}
res = max(res,ans-save[i-1].fi);
}
cout << res;
}
signed main() {
speed;
int tt;
//cin >> tt;
tt = 1;
while ( tt-- ) {
solve();
cout << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |