// ~Be name khoda~ //
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define cl clear
#define endll '\n'
const int maxn = 1e6 + 10;
const int maxn5 = 1e5 + 10;
const int maxnt = 1.2e6 + 10;
const int maxn3 = 1e3 + 10;
const int mod = 1e9 + 7;
const ll inf = 2e18;
ll n, k, t;
set <pair<ll, int>> avl, avr;
multiset <ll> mnl, mnr;
ll x[maxn5], cur[maxn5];
ll val[maxn5], w[maxn5];
inline bool check(ll s){
if(s * t > 2e9)
return true;
for(int i = k - 1; i >= 0; i--){
val[i] = 2 * s * t - x[i + 1] + x[i];
cur[i] = val[i] + cur[i + 1];
w[i] = x[i + 1] - x[i] - cur[i + 1];
}
for(int i = k + 1; i < n; i++){
val[i] = 2 * s * t - x[i] + x[i - 1];
cur[i] = val[i] + cur[i - 1];
w[i] = x[i] - x[i - 1] - cur[i - 1];
}
cur[k] = 0;
int l = k - 1, r = k + 1, lq = k - 1, rq = k + 1;
ll lim = 2 * t * s;
ll lqsum = 0, rqsum = 0;
ll exl = lim, exr = lim;
while(l >= 0 || r < n){
bool re = false;
while(lq >= 0 && w[lq] <= exr){
lqsum += val[lq];
lq--;
if(lqsum >= 0){
exl += lqsum;
lqsum = 0;
l = lq;
re = true;
}
}
while(rq < n && w[rq] <= exl){
rqsum += val[rq];
rq++;
if(rqsum >= 0){
exr += rqsum;
rqsum = 0;
r = rq;
re = true;
}
}
if(!re){
avl.clear();
avr.clear();
mnl.clear();
mnr.clear();
for(int i = 0; i <= l; i++){
avl.insert({-cur[i], i});
mnl.insert(-w[i]);
if(w[i] > exr)
return false;
}
for(int i = r; i < n; i++){
avr.insert({-cur[i], i});
mnr.insert(-w[i]);
if(w[i] > exl)
return false;
}
while(l >= 0 || r < n){
bool re = false;
while(l >= 0 && (r == n || exl + -1 * (avl.begin()->fi) - cur[l + 1] >= -1 * (*mnr.begin()))){
int v = avl.begin() ->se;
while(l >= v){
avl.erase({-cur[l], l});
mnl.erase(mnl.find(-w[l]));
exl += val[l];
l--;
}
re = true;
}
while(r < n && (l < 0 || exr + -1 * (avr.begin()->fi) - cur[r - 1] >= -1 * (*mnl.begin()))){
int v = avr.begin() ->se;
while(r <= v){
avr.erase({-cur[r], r});
mnr.erase(mnr.find(-w[r]));
exr += val[r];
r++;
}
re = true;
}
if(!re)
return false;
}
break;
}
}
return true;
}
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin >> n >> k >> t;
k--;
for(int i = 0; i < n; i++)
cin >> x[i];
ll lo = -1, hi = 1e9 + 1;
while(hi - lo > 1){
ll mid = (lo + hi) >> 1;
if(check(mid))
hi = mid;
else
lo = mid;
}
cout << hi << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
304 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
300 KB |
Output is correct |
18 |
Correct |
0 ms |
324 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
304 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
300 KB |
Output is correct |
18 |
Correct |
0 ms |
324 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
4 ms |
332 KB |
Output is correct |
27 |
Correct |
4 ms |
460 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
30 |
Correct |
3 ms |
460 KB |
Output is correct |
31 |
Correct |
2 ms |
460 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
2 ms |
332 KB |
Output is correct |
34 |
Correct |
3 ms |
332 KB |
Output is correct |
35 |
Correct |
2 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
328 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
2 ms |
332 KB |
Output is correct |
39 |
Correct |
2 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
304 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
300 KB |
Output is correct |
18 |
Correct |
0 ms |
324 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
4 ms |
332 KB |
Output is correct |
27 |
Correct |
4 ms |
460 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
30 |
Correct |
3 ms |
460 KB |
Output is correct |
31 |
Correct |
2 ms |
460 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
2 ms |
332 KB |
Output is correct |
34 |
Correct |
3 ms |
332 KB |
Output is correct |
35 |
Correct |
2 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
328 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
2 ms |
332 KB |
Output is correct |
39 |
Correct |
2 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
33 ms |
4160 KB |
Output is correct |
42 |
Correct |
1 ms |
460 KB |
Output is correct |
43 |
Correct |
20 ms |
2124 KB |
Output is correct |
44 |
Correct |
31 ms |
6124 KB |
Output is correct |
45 |
Correct |
49 ms |
7364 KB |
Output is correct |
46 |
Correct |
50 ms |
7224 KB |
Output is correct |
47 |
Correct |
66 ms |
7628 KB |
Output is correct |
48 |
Correct |
67 ms |
8844 KB |
Output is correct |
49 |
Correct |
28 ms |
4924 KB |
Output is correct |
50 |
Correct |
110 ms |
10352 KB |
Output is correct |
51 |
Correct |
51 ms |
6840 KB |
Output is correct |
52 |
Correct |
261 ms |
13108 KB |
Output is correct |
53 |
Correct |
39 ms |
5188 KB |
Output is correct |
54 |
Correct |
172 ms |
12628 KB |
Output is correct |
55 |
Correct |
70 ms |
8400 KB |
Output is correct |
56 |
Correct |
62 ms |
6256 KB |
Output is correct |
57 |
Correct |
189 ms |
14400 KB |
Output is correct |
58 |
Correct |
106 ms |
9052 KB |
Output is correct |
59 |
Correct |
16 ms |
3524 KB |
Output is correct |
60 |
Correct |
23 ms |
4332 KB |
Output is correct |
61 |
Correct |
27 ms |
4300 KB |
Output is correct |
62 |
Correct |
22 ms |
4396 KB |
Output is correct |
63 |
Correct |
21 ms |
4284 KB |
Output is correct |
64 |
Correct |
21 ms |
4396 KB |
Output is correct |
65 |
Correct |
24 ms |
4400 KB |
Output is correct |
66 |
Correct |
21 ms |
4300 KB |
Output is correct |
67 |
Correct |
20 ms |
4292 KB |
Output is correct |
68 |
Correct |
22 ms |
4404 KB |
Output is correct |
69 |
Correct |
23 ms |
4380 KB |
Output is correct |