#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize("unroll-loops")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr int N = 3e5+20,mod = 998244353 ,inf = 2e9+10,maxm = (1 << 10)+10;
inline int mkay(int a,int b){
if (a+b >= mod) return a+b-mod;
if (a+b < 0) return a+b+mod;
return a+b;
}
inline int poww(int a,int k){
if (k < 0) return 0;
int z = 1;
while (k){
if (k&1) z = 1ll*z*a%mod;
a = 1ll*a*a%mod;
k >>= 1;
}
return z;
}
ll tt;
int n,k,x[N];
ll a[N][2],sum;
pll val(bool f,ll t){
int l = k,r = k;
ll cur = t,sum1 = 0,sum2 = 0;
if (f){
cur = sum;
}
int po1 = l-1,po2 = r+1;
while (1){
bool fl = 0;
while (po1 >= 0 && sum1 <= 0 && sum1-t*f >= -cur){
if (!f && sum1 -x[po1+1]+x[po1] < -cur) break;
// if (f && sum1 -x[k-po1]+x[k-1-po1] < -cur) break;
sum1 += a[po1][f];
po1--;
fl = 1;
}
while (po2 < n && sum2 <= 0 && sum2-f*t >= -cur){
if (!f && sum2 - x[po2]+x[po2-1] < -cur) break;
// if (f && sum2 -x[k-po2]+x[k-po2-1] < -cur) break;
sum2 += a[po2][f];
po2++;
fl = 1;
}
if (sum1 >= 0){
l = po1+1;
cur += sum1;
sum1 = 0;
}
if (sum2 >= 0){
r = po2-1;
cur += sum2;
sum2 = 0;
}
if (!fl) break;
}
return {l,r};
}
inline bool check(ll t){
sum = t;
rep(i,k+1,n){
a[i][0] = t-x[i]+x[i-1];
sum += a[i][0];
}
rep(i,0,k){
a[i][0] = t-x[i+1]+x[i];
sum += a[i][0];
}
if (sum < 0) return 0;
rep(i,0,k)
a[i][1] = -a[k-i-1][0];
rep(i,k+1,n)
a[i][1] = -a[n-i+k][0];
pll p1 = val(1,t),p0 = val(0,t);
// debug(p0.X);
//debug(p1.X);
if (k-p0.X+k-p1.X < k) return 0;
if (p0.Y-k+p1.Y-k < n-k-1) return 0;
return 1;
}
inline int bs(){
int l = -1,r = inf,m;
while (r-l > 1){
m = (l+r) >> 1;
if (check(2*m*tt)) r = m;
else l = m;
}
return r;
}
int main(){
ios :: sync_with_stdio(0); cin.tie(0);
cin >> n >> k >> tt;
k--;
rep(i,0,n) cin >> x[i];
cout << bs();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
22 ms |
2276 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
8 ms |
852 KB |
Output is correct |
44 |
Correct |
31 ms |
3232 KB |
Output is correct |
45 |
Correct |
30 ms |
3120 KB |
Output is correct |
46 |
Correct |
36 ms |
3188 KB |
Output is correct |
47 |
Correct |
31 ms |
3156 KB |
Output is correct |
48 |
Correct |
26 ms |
3148 KB |
Output is correct |
49 |
Correct |
28 ms |
3232 KB |
Output is correct |
50 |
Correct |
28 ms |
3136 KB |
Output is correct |
51 |
Correct |
31 ms |
3160 KB |
Output is correct |
52 |
Correct |
28 ms |
3152 KB |
Output is correct |
53 |
Correct |
32 ms |
3136 KB |
Output is correct |
54 |
Correct |
31 ms |
3228 KB |
Output is correct |
55 |
Correct |
28 ms |
3228 KB |
Output is correct |
56 |
Correct |
28 ms |
3228 KB |
Output is correct |
57 |
Correct |
28 ms |
3156 KB |
Output is correct |
58 |
Correct |
36 ms |
3224 KB |
Output is correct |
59 |
Correct |
24 ms |
2388 KB |
Output is correct |
60 |
Correct |
28 ms |
3156 KB |
Output is correct |
61 |
Correct |
26 ms |
3152 KB |
Output is correct |
62 |
Correct |
28 ms |
3244 KB |
Output is correct |
63 |
Correct |
25 ms |
3156 KB |
Output is correct |
64 |
Correct |
24 ms |
3152 KB |
Output is correct |
65 |
Correct |
33 ms |
3160 KB |
Output is correct |
66 |
Correct |
28 ms |
3128 KB |
Output is correct |
67 |
Correct |
26 ms |
3196 KB |
Output is correct |
68 |
Correct |
25 ms |
3128 KB |
Output is correct |
69 |
Correct |
26 ms |
3168 KB |
Output is correct |