#include<bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
#define int ll
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mispertion ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define F first
#define S second
#define getlast(s) (*s.rbegin())
#define debg cout << "OK\n"
const ld PI = 3.1415926535;
const int N = 500000+1;
const int M = 7e6 + 1;
int mod = 998244353;
const int infi = INT_MAX;
const ll infl = LLONG_MAX;
const int P = 31;
int mult(int a, int b) {
return a * 1LL * b % mod;
}
int sum(int a, int b) {
if (a + b < 0)
return a + b + mod;
if (a + b >= mod)
return a + b - mod;
return a + b;
}
ll binpow(ll a, ll n) {
if (n == 0)
return 1;
if (n % 2 == 1) {
return binpow(a, n - 1) * a % mod;
} else {
ll b = binpow(a, n / 2);
return b * b % mod;
}
}
int a[N], b[N], n, pr[N];
vector<pii> v;
void solve(){
cin >> n;
v.resize(n);
for(int i = 1; i <= n; i++){
int x, y;
cin >> x >> y;
v[i - 1] = {x, y};
}
sort(all(v));
for(int i = 0; i < n; i++)
a[i + 1] = v[i].F, b[i + 1] = v[i].S;
for(int i = 1; i <= n; i++)
pr[i] = pr[i - 1] + b[i];
set<pii> st;
int ans = 0;
for(int i = 1; i <= n; i++){
st.insert({-pr[i - 1] + a[i], i});
int ps = st.rbegin()->S;
ans = max(ans, a[ps] - a[i] + pr[i] - pr[ps - 1]);
}
cout << ans << '\n';
}
signed main() {
mispertion;
int t = 1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
3 ms |
4956 KB |
Output is correct |
28 |
Correct |
3 ms |
4952 KB |
Output is correct |
29 |
Correct |
3 ms |
4952 KB |
Output is correct |
30 |
Correct |
3 ms |
4956 KB |
Output is correct |
31 |
Correct |
3 ms |
4956 KB |
Output is correct |
32 |
Correct |
3 ms |
4956 KB |
Output is correct |
33 |
Correct |
3 ms |
4956 KB |
Output is correct |
34 |
Correct |
2 ms |
4956 KB |
Output is correct |
35 |
Correct |
3 ms |
4952 KB |
Output is correct |
36 |
Correct |
3 ms |
4956 KB |
Output is correct |
37 |
Correct |
3 ms |
4956 KB |
Output is correct |
38 |
Correct |
3 ms |
4956 KB |
Output is correct |
39 |
Correct |
6 ms |
4956 KB |
Output is correct |
40 |
Correct |
3 ms |
4956 KB |
Output is correct |
41 |
Correct |
3 ms |
4956 KB |
Output is correct |
42 |
Correct |
4 ms |
4900 KB |
Output is correct |
43 |
Correct |
3 ms |
5140 KB |
Output is correct |
44 |
Correct |
3 ms |
4952 KB |
Output is correct |
45 |
Correct |
3 ms |
4956 KB |
Output is correct |
46 |
Correct |
3 ms |
4956 KB |
Output is correct |
47 |
Correct |
2 ms |
4956 KB |
Output is correct |
48 |
Correct |
2 ms |
4956 KB |
Output is correct |
49 |
Correct |
2 ms |
4956 KB |
Output is correct |
50 |
Correct |
3 ms |
4952 KB |
Output is correct |
51 |
Correct |
3 ms |
4956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
3 ms |
4956 KB |
Output is correct |
28 |
Correct |
3 ms |
4952 KB |
Output is correct |
29 |
Correct |
3 ms |
4952 KB |
Output is correct |
30 |
Correct |
3 ms |
4956 KB |
Output is correct |
31 |
Correct |
3 ms |
4956 KB |
Output is correct |
32 |
Correct |
3 ms |
4956 KB |
Output is correct |
33 |
Correct |
3 ms |
4956 KB |
Output is correct |
34 |
Correct |
2 ms |
4956 KB |
Output is correct |
35 |
Correct |
3 ms |
4952 KB |
Output is correct |
36 |
Correct |
3 ms |
4956 KB |
Output is correct |
37 |
Correct |
3 ms |
4956 KB |
Output is correct |
38 |
Correct |
3 ms |
4956 KB |
Output is correct |
39 |
Correct |
6 ms |
4956 KB |
Output is correct |
40 |
Correct |
3 ms |
4956 KB |
Output is correct |
41 |
Correct |
3 ms |
4956 KB |
Output is correct |
42 |
Correct |
4 ms |
4900 KB |
Output is correct |
43 |
Correct |
3 ms |
5140 KB |
Output is correct |
44 |
Correct |
3 ms |
4952 KB |
Output is correct |
45 |
Correct |
3 ms |
4956 KB |
Output is correct |
46 |
Correct |
3 ms |
4956 KB |
Output is correct |
47 |
Correct |
2 ms |
4956 KB |
Output is correct |
48 |
Correct |
2 ms |
4956 KB |
Output is correct |
49 |
Correct |
2 ms |
4956 KB |
Output is correct |
50 |
Correct |
3 ms |
4952 KB |
Output is correct |
51 |
Correct |
3 ms |
4956 KB |
Output is correct |
52 |
Correct |
201 ms |
51316 KB |
Output is correct |
53 |
Correct |
201 ms |
51256 KB |
Output is correct |
54 |
Correct |
207 ms |
51280 KB |
Output is correct |
55 |
Correct |
214 ms |
51284 KB |
Output is correct |
56 |
Correct |
234 ms |
51540 KB |
Output is correct |
57 |
Correct |
263 ms |
51284 KB |
Output is correct |
58 |
Correct |
224 ms |
51284 KB |
Output is correct |
59 |
Correct |
237 ms |
51104 KB |
Output is correct |
60 |
Correct |
219 ms |
51296 KB |
Output is correct |
61 |
Correct |
216 ms |
51296 KB |
Output is correct |
62 |
Correct |
230 ms |
51304 KB |
Output is correct |
63 |
Correct |
216 ms |
51284 KB |
Output is correct |
64 |
Correct |
239 ms |
51292 KB |
Output is correct |
65 |
Correct |
200 ms |
51280 KB |
Output is correct |
66 |
Correct |
192 ms |
51268 KB |
Output is correct |
67 |
Correct |
204 ms |
51296 KB |
Output is correct |
68 |
Correct |
227 ms |
51300 KB |
Output is correct |