#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pll;
vector <pll> L, R;
ll X[101010], D[101010];
ll n, k, t;
bool check(ll v)
{
ll i, j, l, r, f, l1, l2, r1, r2;
for(i=1; i<=n; i++){
D[i] = 2 * v * t * i - X[i];
}
if(D[1] > D[n]) return 0;
for(l=k, r=k, i=k-1, j=k+1, f=0; ; f=0){
for(; i >= 1 && D[i] > D[l] && D[i] <= D[r]; i--);
for(; j <= n && D[j] < D[r] && D[j] >= D[l]; j++);
if(i >= 1 && D[i] <= D[l]) l = i --, f = 1;
if(j <= n && D[j] >= D[r]) r = j ++, f = 1;
if(!f) break;
}
l1 = l; r1 = r;
for(l=1, r=n, i=2, j=n-1, f=0; ; f=0){
for(; i <= k && D[i] > D[l] && D[i] <= D[r]; i++);
for(; j >= k && D[j] < D[r] && D[j] >= D[l]; j--);
if(i <= k && D[i] <= D[l]) l = i ++, f = 1;
if(j >= k && D[j] >= D[r]) r = j --, f = 1;
if(!f) break;
}
l2 = l; r2 = r;
return (l1 <= l2) && (r2 <= r1);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
ll i, s, e;
cin >> n >> k >> t;
for(i=1; i<=n; i++){
cin >> X[i];
}
for(s=0, e=1e12/t; s<=e; ){
if(check(s + e >> 1)) e = (s + e >> 1) - 1;
else s = (s + e >> 1) + 1;
}
cout << e + 1 << "\n";
return 0;
}
Compilation message
sparklers.cpp: In function 'int main()':
sparklers.cpp:61:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
if(check(s + e >> 1)) e = (s + e >> 1) - 1;
~~^~~
sparklers.cpp:61:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
if(check(s + e >> 1)) e = (s + e >> 1) - 1;
~~^~~
sparklers.cpp:62:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
else s = (s + e >> 1) + 1;
~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
452 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
3 ms |
376 KB |
Output is correct |
34 |
Correct |
3 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
3 ms |
380 KB |
Output is correct |
38 |
Correct |
2 ms |
404 KB |
Output is correct |
39 |
Correct |
2 ms |
376 KB |
Output is correct |
40 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
380 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
29 |
Correct |
2 ms |
376 KB |
Output is correct |
30 |
Correct |
2 ms |
376 KB |
Output is correct |
31 |
Correct |
2 ms |
452 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
33 |
Correct |
3 ms |
376 KB |
Output is correct |
34 |
Correct |
3 ms |
376 KB |
Output is correct |
35 |
Correct |
2 ms |
376 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
3 ms |
380 KB |
Output is correct |
38 |
Correct |
2 ms |
404 KB |
Output is correct |
39 |
Correct |
2 ms |
376 KB |
Output is correct |
40 |
Correct |
2 ms |
376 KB |
Output is correct |
41 |
Correct |
20 ms |
1400 KB |
Output is correct |
42 |
Correct |
3 ms |
380 KB |
Output is correct |
43 |
Correct |
7 ms |
632 KB |
Output is correct |
44 |
Correct |
28 ms |
1912 KB |
Output is correct |
45 |
Correct |
28 ms |
1912 KB |
Output is correct |
46 |
Correct |
30 ms |
1912 KB |
Output is correct |
47 |
Correct |
33 ms |
1912 KB |
Output is correct |
48 |
Correct |
30 ms |
1912 KB |
Output is correct |
49 |
Correct |
29 ms |
1912 KB |
Output is correct |
50 |
Correct |
29 ms |
1912 KB |
Output is correct |
51 |
Correct |
31 ms |
2040 KB |
Output is correct |
52 |
Correct |
30 ms |
1912 KB |
Output is correct |
53 |
Correct |
32 ms |
1912 KB |
Output is correct |
54 |
Correct |
30 ms |
1912 KB |
Output is correct |
55 |
Correct |
31 ms |
1912 KB |
Output is correct |
56 |
Correct |
30 ms |
1912 KB |
Output is correct |
57 |
Correct |
31 ms |
1912 KB |
Output is correct |
58 |
Correct |
29 ms |
1912 KB |
Output is correct |
59 |
Correct |
22 ms |
1912 KB |
Output is correct |
60 |
Correct |
27 ms |
1884 KB |
Output is correct |
61 |
Correct |
27 ms |
2040 KB |
Output is correct |
62 |
Correct |
28 ms |
1912 KB |
Output is correct |
63 |
Correct |
27 ms |
1912 KB |
Output is correct |
64 |
Correct |
27 ms |
1912 KB |
Output is correct |
65 |
Correct |
30 ms |
1912 KB |
Output is correct |
66 |
Correct |
28 ms |
1912 KB |
Output is correct |
67 |
Correct |
31 ms |
1912 KB |
Output is correct |
68 |
Correct |
28 ms |
1912 KB |
Output is correct |
69 |
Correct |
28 ms |
1912 KB |
Output is correct |