#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool ok(int n, int k, vector<int>&ve, ll m){
vector<ll> v(n);
for(int i=0;i<n;i++) v[i] = ve[i] - 2*m*i;
//for(int i : v) cout<<i<<' '; cout<<endl;
int bl = k-1, sr = k-1;
for(int i=k-1;i>=0;i--) if(v[i] > v[bl]) bl=i;
for(int i=k-1;i<n;i++) if(v[i] < v[sr]) sr=i;
int nl=k-1, nr=k-1;
ll mxl=v[k-1], mnr=v[k-1];
while(nl > bl || nr < sr){
int nnr=nr, nnl=nl;
while(nl>bl && v[nl-1]>=mnr){ nl--; if(v[nl] > mxl) mxl=v[nl]; }
while(nr<sr && v[nr+1]<=mxl){ nr++; if(v[nr] < mnr) mnr=v[nr]; }
if(nnr==nr && nnl==nl) break;
}
if(nl > bl || nr < sr)return 0;
nl=0; nr=n-1;
mxl=v[0]; mnr=v[n-1];
if(mnr > mxl) return 0;
while(nl < bl || nr > sr){
int nnr=nr, nnl=nl;
while(nl<bl && v[nl+1]>=mnr){ nl++; if(v[nl] > mxl) mxl=v[nl]; }
while(nr>sr && v[nr-1]<=mxl){ nr--; if(v[nr] < mnr) mnr=v[nr]; }
if(nnr==nr && nnl==nl) break;
}
if(nl < bl || nr > sr)return 0;
return 1;
/*bool dp[n][n];
for(int i=0;i<n;i++)for(int j=0;j<n;j++) dp[i][j]=0;
dp[k-1][k-1]=1;
for(int sz=2;sz<=n;sz++){
for(int i=0;i+sz-1 < n;i++){
if((v[i+sz-1] <= v[i]) && (dp[i][i+sz-2] || dp[i+1][i+sz-1])) dp[i][i+sz-1]=1;
}
}
return dp[0][n-1];*/
}
int func(int n, int k, int t, vector<int>&v){
int s=0, e=1e9, m;
while(e>s){
m = (e+s)/2;
if(ok(n,k,v,m)) e=m;
else s=m+1;
}
return (s+t-1)/t;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
int n,k,t;
cin>>n>>k>>t;
vector<int> v(n);
for(int i=0;i<n;i++) cin>>v[i];
int res = func(n,k,t,v);
cout<<res<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
404 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
404 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
15 ms |
1884 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
5 ms |
828 KB |
Output is correct |
44 |
Correct |
21 ms |
2608 KB |
Output is correct |
45 |
Correct |
21 ms |
2396 KB |
Output is correct |
46 |
Correct |
21 ms |
2396 KB |
Output is correct |
47 |
Correct |
22 ms |
2596 KB |
Output is correct |
48 |
Correct |
21 ms |
2380 KB |
Output is correct |
49 |
Correct |
21 ms |
2604 KB |
Output is correct |
50 |
Correct |
21 ms |
2396 KB |
Output is correct |
51 |
Correct |
21 ms |
2384 KB |
Output is correct |
52 |
Correct |
21 ms |
2392 KB |
Output is correct |
53 |
Correct |
21 ms |
2504 KB |
Output is correct |
54 |
Correct |
21 ms |
2396 KB |
Output is correct |
55 |
Correct |
21 ms |
2396 KB |
Output is correct |
56 |
Correct |
21 ms |
2592 KB |
Output is correct |
57 |
Correct |
22 ms |
2392 KB |
Output is correct |
58 |
Correct |
21 ms |
2396 KB |
Output is correct |
59 |
Correct |
18 ms |
1628 KB |
Output is correct |
60 |
Correct |
21 ms |
2396 KB |
Output is correct |
61 |
Correct |
21 ms |
2396 KB |
Output is correct |
62 |
Correct |
20 ms |
2392 KB |
Output is correct |
63 |
Correct |
21 ms |
2396 KB |
Output is correct |
64 |
Correct |
24 ms |
2392 KB |
Output is correct |
65 |
Correct |
21 ms |
2616 KB |
Output is correct |
66 |
Correct |
21 ms |
2520 KB |
Output is correct |
67 |
Correct |
21 ms |
2396 KB |
Output is correct |
68 |
Correct |
21 ms |
2576 KB |
Output is correct |
69 |
Correct |
21 ms |
2588 KB |
Output is correct |