#include<bits/stdc++.h>
using namespace std;
int L, R, N, K, T, x[100009], stk[100009];
long long v[100009], mi[100009], ma[100009];
pair < int, long long > lft[100009], rgt[100009];
bool firstPart ()
{
int nr = 0;
for (int i=1; i<=K; i++)
{
while (nr > 0 && v[stk[nr]] < v[i])
mi[nr - 1] = min (mi[nr - 1], mi[nr]), nr --;
if (nr == 0) L = i;
else lft[i] = {stk[nr], mi[nr]};
stk[++nr] = i, mi[nr] = v[i];
}
nr = 0;
for (int i=N; i>=K; i--)
{
while (nr > 0 && v[stk[nr]] > v[i])
ma[nr - 1] = max (ma[nr - 1], ma[nr]), nr --;
if (nr == 0) R = i;
else rgt[i] = {stk[nr], ma[nr]};
stk[++nr] = i, ma[nr] = v[i];
}
int l = K, r = K;
bool change = 1;
while (change)
{
change = 0;
if (l != L && lft[l].second >= v[r])
l = lft[l].first, change = 1;
if (r != R && rgt[r].second <= v[l])
r = rgt[r].first, change = 1;
}
return (l == L && r == R);
}
bool secondPart ()
{
if (v[1] < v[N]) return 0;
int nr = 0;
for (int i=K; i>=1; i--)
{
while (nr > 0 && v[stk[nr]] <= v[i])
mi[nr - 1] = min (mi[nr - 1], mi[nr]), nr --;
if (nr == 0) L = i;
else lft[i] = {stk[nr], mi[nr]};
stk[++nr] = i, mi[nr] = v[i];
}
nr = 0;
for (int i=K; i<=N; i++)
{
while (nr > 0 && v[stk[nr]] >= v[i])
ma[nr - 1] = max (ma[nr - 1], ma[nr]), nr --;
if (nr == 0) R = i;
else rgt[i] = {stk[nr], ma[nr]};
stk[++nr] = i, ma[nr] = v[i];
}
int l = 1, r = N;
bool change = 1;
while (change)
{
change = 0;
if (l != L && lft[l].second >= v[r])
l = lft[l].first, change = 1;
if (r != R && rgt[r].second <= v[l])
r = rgt[r].first, change = 1;
}
return (l == L && r == R);
}
bool ok (int S)
{
for (int i=1; i<=N; i++)
v[i] = x[i] - 2LL * i * S * T;
if (!firstPart ()) return 0;
if (!secondPart ()) return 0;
return 1;
}
int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);
scanf ("%d %d %d", &N, &K, &T);
for (int i=1; i<=N; i++)
scanf ("%d", &x[i]);
int p = 0, u = (x[N] - x[1]) / T + 1, mij, ras = -1;
while (p <= u)
{
mij = (p + u) >> 1;
if (ok (mij)) ras = mij, u = mij - 1;
else p = mij + 1;
}
printf ("%d\n", ras);
return 0;
}
Compilation message
sparklers.cpp: In function 'int main()':
sparklers.cpp:90:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d %d %d", &N, &K, &T);
~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:92:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d", &x[i]);
~~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
480 KB |
Output is correct |
5 |
Correct |
2 ms |
612 KB |
Output is correct |
6 |
Correct |
3 ms |
612 KB |
Output is correct |
7 |
Correct |
2 ms |
612 KB |
Output is correct |
8 |
Correct |
2 ms |
728 KB |
Output is correct |
9 |
Correct |
2 ms |
728 KB |
Output is correct |
10 |
Correct |
2 ms |
780 KB |
Output is correct |
11 |
Correct |
2 ms |
780 KB |
Output is correct |
12 |
Correct |
2 ms |
780 KB |
Output is correct |
13 |
Correct |
2 ms |
780 KB |
Output is correct |
14 |
Correct |
2 ms |
784 KB |
Output is correct |
15 |
Correct |
2 ms |
788 KB |
Output is correct |
16 |
Correct |
2 ms |
788 KB |
Output is correct |
17 |
Correct |
2 ms |
800 KB |
Output is correct |
18 |
Correct |
2 ms |
800 KB |
Output is correct |
19 |
Correct |
2 ms |
808 KB |
Output is correct |
20 |
Correct |
2 ms |
812 KB |
Output is correct |
21 |
Correct |
2 ms |
816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
480 KB |
Output is correct |
5 |
Correct |
2 ms |
612 KB |
Output is correct |
6 |
Correct |
3 ms |
612 KB |
Output is correct |
7 |
Correct |
2 ms |
612 KB |
Output is correct |
8 |
Correct |
2 ms |
728 KB |
Output is correct |
9 |
Correct |
2 ms |
728 KB |
Output is correct |
10 |
Correct |
2 ms |
780 KB |
Output is correct |
11 |
Correct |
2 ms |
780 KB |
Output is correct |
12 |
Correct |
2 ms |
780 KB |
Output is correct |
13 |
Correct |
2 ms |
780 KB |
Output is correct |
14 |
Correct |
2 ms |
784 KB |
Output is correct |
15 |
Correct |
2 ms |
788 KB |
Output is correct |
16 |
Correct |
2 ms |
788 KB |
Output is correct |
17 |
Correct |
2 ms |
800 KB |
Output is correct |
18 |
Correct |
2 ms |
800 KB |
Output is correct |
19 |
Correct |
2 ms |
808 KB |
Output is correct |
20 |
Correct |
2 ms |
812 KB |
Output is correct |
21 |
Correct |
2 ms |
816 KB |
Output is correct |
22 |
Correct |
2 ms |
820 KB |
Output is correct |
23 |
Correct |
2 ms |
828 KB |
Output is correct |
24 |
Correct |
2 ms |
852 KB |
Output is correct |
25 |
Correct |
2 ms |
876 KB |
Output is correct |
26 |
Correct |
3 ms |
940 KB |
Output is correct |
27 |
Correct |
2 ms |
940 KB |
Output is correct |
28 |
Correct |
2 ms |
940 KB |
Output is correct |
29 |
Correct |
2 ms |
940 KB |
Output is correct |
30 |
Correct |
2 ms |
944 KB |
Output is correct |
31 |
Correct |
2 ms |
948 KB |
Output is correct |
32 |
Correct |
2 ms |
980 KB |
Output is correct |
33 |
Correct |
2 ms |
988 KB |
Output is correct |
34 |
Correct |
3 ms |
1000 KB |
Output is correct |
35 |
Correct |
3 ms |
1028 KB |
Output is correct |
36 |
Correct |
2 ms |
1040 KB |
Output is correct |
37 |
Correct |
3 ms |
1052 KB |
Output is correct |
38 |
Correct |
2 ms |
1064 KB |
Output is correct |
39 |
Correct |
3 ms |
1076 KB |
Output is correct |
40 |
Correct |
2 ms |
1088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
480 KB |
Output is correct |
5 |
Correct |
2 ms |
612 KB |
Output is correct |
6 |
Correct |
3 ms |
612 KB |
Output is correct |
7 |
Correct |
2 ms |
612 KB |
Output is correct |
8 |
Correct |
2 ms |
728 KB |
Output is correct |
9 |
Correct |
2 ms |
728 KB |
Output is correct |
10 |
Correct |
2 ms |
780 KB |
Output is correct |
11 |
Correct |
2 ms |
780 KB |
Output is correct |
12 |
Correct |
2 ms |
780 KB |
Output is correct |
13 |
Correct |
2 ms |
780 KB |
Output is correct |
14 |
Correct |
2 ms |
784 KB |
Output is correct |
15 |
Correct |
2 ms |
788 KB |
Output is correct |
16 |
Correct |
2 ms |
788 KB |
Output is correct |
17 |
Correct |
2 ms |
800 KB |
Output is correct |
18 |
Correct |
2 ms |
800 KB |
Output is correct |
19 |
Correct |
2 ms |
808 KB |
Output is correct |
20 |
Correct |
2 ms |
812 KB |
Output is correct |
21 |
Correct |
2 ms |
816 KB |
Output is correct |
22 |
Correct |
2 ms |
820 KB |
Output is correct |
23 |
Correct |
2 ms |
828 KB |
Output is correct |
24 |
Correct |
2 ms |
852 KB |
Output is correct |
25 |
Correct |
2 ms |
876 KB |
Output is correct |
26 |
Correct |
3 ms |
940 KB |
Output is correct |
27 |
Correct |
2 ms |
940 KB |
Output is correct |
28 |
Correct |
2 ms |
940 KB |
Output is correct |
29 |
Correct |
2 ms |
940 KB |
Output is correct |
30 |
Correct |
2 ms |
944 KB |
Output is correct |
31 |
Correct |
2 ms |
948 KB |
Output is correct |
32 |
Correct |
2 ms |
980 KB |
Output is correct |
33 |
Correct |
2 ms |
988 KB |
Output is correct |
34 |
Correct |
3 ms |
1000 KB |
Output is correct |
35 |
Correct |
3 ms |
1028 KB |
Output is correct |
36 |
Correct |
2 ms |
1040 KB |
Output is correct |
37 |
Correct |
3 ms |
1052 KB |
Output is correct |
38 |
Correct |
2 ms |
1064 KB |
Output is correct |
39 |
Correct |
3 ms |
1076 KB |
Output is correct |
40 |
Correct |
2 ms |
1088 KB |
Output is correct |
41 |
Correct |
32 ms |
4164 KB |
Output is correct |
42 |
Correct |
4 ms |
4164 KB |
Output is correct |
43 |
Correct |
12 ms |
4164 KB |
Output is correct |
44 |
Correct |
73 ms |
6728 KB |
Output is correct |
45 |
Correct |
71 ms |
7692 KB |
Output is correct |
46 |
Correct |
68 ms |
8656 KB |
Output is correct |
47 |
Correct |
67 ms |
9624 KB |
Output is correct |
48 |
Correct |
72 ms |
10584 KB |
Output is correct |
49 |
Correct |
71 ms |
11672 KB |
Output is correct |
50 |
Correct |
73 ms |
12380 KB |
Output is correct |
51 |
Correct |
68 ms |
13596 KB |
Output is correct |
52 |
Correct |
75 ms |
14436 KB |
Output is correct |
53 |
Correct |
74 ms |
15408 KB |
Output is correct |
54 |
Correct |
53 ms |
16376 KB |
Output is correct |
55 |
Correct |
67 ms |
17204 KB |
Output is correct |
56 |
Correct |
69 ms |
18296 KB |
Output is correct |
57 |
Correct |
71 ms |
19308 KB |
Output is correct |
58 |
Correct |
63 ms |
20136 KB |
Output is correct |
59 |
Correct |
14 ms |
20296 KB |
Output is correct |
60 |
Correct |
57 ms |
21452 KB |
Output is correct |
61 |
Correct |
48 ms |
22348 KB |
Output is correct |
62 |
Correct |
53 ms |
23228 KB |
Output is correct |
63 |
Correct |
52 ms |
24116 KB |
Output is correct |
64 |
Correct |
52 ms |
25168 KB |
Output is correct |
65 |
Correct |
50 ms |
26004 KB |
Output is correct |
66 |
Correct |
48 ms |
26968 KB |
Output is correct |
67 |
Correct |
51 ms |
28044 KB |
Output is correct |
68 |
Correct |
53 ms |
29036 KB |
Output is correct |
69 |
Correct |
79 ms |
29964 KB |
Output is correct |