#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, k;
ll s;
ll arr[100002];
bool able(vector<ll> &v1, vector<ll> &v2){
vector<pair<ll, ll> > vp1, vp2;
ll prvMin = v1[0], tmpMax = v1[0];
for(ll x: v1){
tmpMax = max(tmpMax, x);
if(x < prvMin){
vp1.push_back(make_pair(tmpMax, x));
prvMin = tmpMax = x;
}
}
ll prvMax = v2[0], tmpMin = v2[0];
for(ll x: v2){
tmpMin = min(tmpMin, x);
if(x > prvMax){
vp2.push_back(make_pair(tmpMin, x));
prvMax = tmpMin = x;
}
}
reverse(vp1.begin(), vp1.end());
reverse(vp2.begin(), vp2.end());
ll L = v1[0], R = v2[0];
while(!vp1.empty() || !vp2.empty()){
if(!vp1.empty() && vp1.back().first <= R){
L = vp1.back().second;
vp1.pop_back();
}
else if(!vp2.empty() && vp2.back().first >= L){
R = vp2.back().second;
vp2.pop_back();
}
else return false;
}
return true;
}
bool able(ll speed){
speed = min(speed * s * 2, ll(1e9));
vector<ll> vecL, vecR;
for(int i=k; i>=1; i--){
vecL.push_back(speed * i - arr[i]);
}
for(int i=k; i<=n; i++){
vecR.push_back(speed * i - arr[i]);
}
if(*max_element(vecL.begin(), vecL.end()) > *max_element(vecR.begin(), vecR.end())) return false;
if(*min_element(vecL.begin(), vecL.end()) > *min_element(vecL.begin(), vecL.end())) return false;
if(vecL.back() > vecR.back()) return false;
auto it1 = min_element(vecL.begin(), vecL.end());
auto it2 = max_element(vecR.begin(), vecR.end());
vector<ll> vecL1(vecL.begin(), it1+1), vecL2(it1, vecL.end());
vector<ll> vecR1(vecR.begin(), it2+1), vecR2(it2, vecR.end());
reverse(vecL2.begin(), vecL2.end());
reverse(vecR2.begin(), vecR2.end());
if(!able(vecL1, vecR1)) return false;
if(!able(vecL2, vecR2)) return false;
return true;
}
int main(){
scanf("%d %d %lld", &n, &k, &s);
for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
if(arr[1] == arr[n]){
puts("0");
return 0;
}
ll MIN = 1, MAX = 1e9, ANS = 1e9;
while(MIN <= MAX){
ll MID = (MIN + MAX) / 2;
if(able(MID)) ANS = MID, MAX = MID-1;
else MIN = MID+1;
}
printf("%lld", ANS);
}
Compilation message
sparklers.cpp: In function 'int main()':
sparklers.cpp:72:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | scanf("%d %d %lld", &n, &k, &s);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:73:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
0 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
316 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
0 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
316 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
316 KB |
Output is correct |
24 |
Correct |
1 ms |
312 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
320 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 |
320 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 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 |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
0 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
308 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
316 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
316 KB |
Output is correct |
24 |
Correct |
1 ms |
312 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
320 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 |
320 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 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 |
308 KB |
Output is correct |
41 |
Correct |
52 ms |
4408 KB |
Output is correct |
42 |
Correct |
2 ms |
500 KB |
Output is correct |
43 |
Correct |
13 ms |
1496 KB |
Output is correct |
44 |
Correct |
72 ms |
7564 KB |
Output is correct |
45 |
Correct |
67 ms |
6232 KB |
Output is correct |
46 |
Correct |
70 ms |
7384 KB |
Output is correct |
47 |
Correct |
82 ms |
7420 KB |
Output is correct |
48 |
Correct |
79 ms |
6316 KB |
Output is correct |
49 |
Correct |
76 ms |
7404 KB |
Output is correct |
50 |
Correct |
71 ms |
6304 KB |
Output is correct |
51 |
Correct |
83 ms |
7388 KB |
Output is correct |
52 |
Correct |
82 ms |
7164 KB |
Output is correct |
53 |
Correct |
76 ms |
7308 KB |
Output is correct |
54 |
Correct |
92 ms |
7100 KB |
Output is correct |
55 |
Correct |
69 ms |
6316 KB |
Output is correct |
56 |
Correct |
78 ms |
7884 KB |
Output is correct |
57 |
Correct |
78 ms |
7260 KB |
Output is correct |
58 |
Correct |
81 ms |
6288 KB |
Output is correct |
59 |
Correct |
7 ms |
1236 KB |
Output is correct |
60 |
Correct |
75 ms |
7188 KB |
Output is correct |
61 |
Correct |
78 ms |
6964 KB |
Output is correct |
62 |
Correct |
66 ms |
7484 KB |
Output is correct |
63 |
Correct |
70 ms |
6872 KB |
Output is correct |
64 |
Correct |
69 ms |
6228 KB |
Output is correct |
65 |
Correct |
72 ms |
6232 KB |
Output is correct |
66 |
Correct |
66 ms |
6232 KB |
Output is correct |
67 |
Correct |
71 ms |
6376 KB |
Output is correct |
68 |
Correct |
76 ms |
7208 KB |
Output is correct |
69 |
Correct |
75 ms |
7216 KB |
Output is correct |