#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define ll long long
#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define OK puts("ok");
#define whatis(x) cerr << #x << " = " << x << endl;
#define pause system("pause");
#define ld long double
const ll N = (int)1e5 + 7;
const int inf = (int)1e9 + 7;
int mod = (int)1e9 + 7;
int n, k, t;
int X[N];
bool make(vector < ld > x, vector < ld > y) {
if (x[0] < y[0]) return 0;
int ok = 1;
pii L, R;
L = mk(0, 0);
R = mk(0, 0);
while (ok) {
ok = 0;
while (L.fr + 1 < sz(x) && x[L.fr + 1] >= y[R.sc]) {
ok = 1;
if (x[++L.fr] > x[L.sc]) L.sc = L.fr;
}
while (R.fr + 1 < sz(y) && y[R.fr + 1] <= x[L.sc]) {
ok = 1;
if (y[++R.fr] < y[R.sc]) R.sc = R.fr;
}
}
return L.fr + 1 == sz(x) && R.fr + 1 == sz(y);
}
bool check(int s) {
vector < ld > x, y;
for (ll i = k; i >= 0; i--)
x.pb(X[i] - (ld)2 * s * t * i);
for (ll i = k; i < n; i++)
y.pb(X[i] - (ld)2 * s * t * i);
if (!make(x, y)) return 0;
reverse(all(x));
reverse(all(y));
if (!make(x, y)) return 0;
return 1;
}
main() {
cin >> n >> k >> t;
k--;
for (ll i = 0; i < n; i++) {
cin >> X[i];
}
int l = 0;
int r = 1e9;
while (l < r) {
ll mid = (l + r) / 2;
if (check(mid)) {
r = mid;
} else {
l = mid + 1;
}
}
cout << l;
}
Compilation message
sparklers.cpp:58:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
3 ms |
548 KB |
Output is correct |
4 |
Correct |
2 ms |
548 KB |
Output is correct |
5 |
Correct |
3 ms |
548 KB |
Output is correct |
6 |
Correct |
3 ms |
548 KB |
Output is correct |
7 |
Correct |
3 ms |
568 KB |
Output is correct |
8 |
Correct |
2 ms |
568 KB |
Output is correct |
9 |
Correct |
2 ms |
576 KB |
Output is correct |
10 |
Correct |
2 ms |
576 KB |
Output is correct |
11 |
Correct |
2 ms |
576 KB |
Output is correct |
12 |
Correct |
2 ms |
576 KB |
Output is correct |
13 |
Correct |
3 ms |
632 KB |
Output is correct |
14 |
Correct |
3 ms |
632 KB |
Output is correct |
15 |
Correct |
3 ms |
632 KB |
Output is correct |
16 |
Correct |
2 ms |
632 KB |
Output is correct |
17 |
Correct |
4 ms |
632 KB |
Output is correct |
18 |
Correct |
2 ms |
648 KB |
Output is correct |
19 |
Correct |
2 ms |
648 KB |
Output is correct |
20 |
Correct |
3 ms |
648 KB |
Output is correct |
21 |
Correct |
3 ms |
648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
3 ms |
548 KB |
Output is correct |
4 |
Correct |
2 ms |
548 KB |
Output is correct |
5 |
Correct |
3 ms |
548 KB |
Output is correct |
6 |
Correct |
3 ms |
548 KB |
Output is correct |
7 |
Correct |
3 ms |
568 KB |
Output is correct |
8 |
Correct |
2 ms |
568 KB |
Output is correct |
9 |
Correct |
2 ms |
576 KB |
Output is correct |
10 |
Correct |
2 ms |
576 KB |
Output is correct |
11 |
Correct |
2 ms |
576 KB |
Output is correct |
12 |
Correct |
2 ms |
576 KB |
Output is correct |
13 |
Correct |
3 ms |
632 KB |
Output is correct |
14 |
Correct |
3 ms |
632 KB |
Output is correct |
15 |
Correct |
3 ms |
632 KB |
Output is correct |
16 |
Correct |
2 ms |
632 KB |
Output is correct |
17 |
Correct |
4 ms |
632 KB |
Output is correct |
18 |
Correct |
2 ms |
648 KB |
Output is correct |
19 |
Correct |
2 ms |
648 KB |
Output is correct |
20 |
Correct |
3 ms |
648 KB |
Output is correct |
21 |
Correct |
3 ms |
648 KB |
Output is correct |
22 |
Correct |
5 ms |
676 KB |
Output is correct |
23 |
Correct |
3 ms |
676 KB |
Output is correct |
24 |
Correct |
4 ms |
688 KB |
Output is correct |
25 |
Correct |
4 ms |
700 KB |
Output is correct |
26 |
Correct |
5 ms |
716 KB |
Output is correct |
27 |
Correct |
5 ms |
716 KB |
Output is correct |
28 |
Correct |
5 ms |
752 KB |
Output is correct |
29 |
Correct |
3 ms |
752 KB |
Output is correct |
30 |
Correct |
5 ms |
760 KB |
Output is correct |
31 |
Correct |
4 ms |
772 KB |
Output is correct |
32 |
Correct |
5 ms |
860 KB |
Output is correct |
33 |
Correct |
4 ms |
860 KB |
Output is correct |
34 |
Correct |
4 ms |
860 KB |
Output is correct |
35 |
Correct |
4 ms |
860 KB |
Output is correct |
36 |
Correct |
4 ms |
860 KB |
Output is correct |
37 |
Correct |
5 ms |
860 KB |
Output is correct |
38 |
Correct |
4 ms |
860 KB |
Output is correct |
39 |
Correct |
4 ms |
868 KB |
Output is correct |
40 |
Correct |
4 ms |
880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
3 ms |
548 KB |
Output is correct |
4 |
Correct |
2 ms |
548 KB |
Output is correct |
5 |
Correct |
3 ms |
548 KB |
Output is correct |
6 |
Correct |
3 ms |
548 KB |
Output is correct |
7 |
Correct |
3 ms |
568 KB |
Output is correct |
8 |
Correct |
2 ms |
568 KB |
Output is correct |
9 |
Correct |
2 ms |
576 KB |
Output is correct |
10 |
Correct |
2 ms |
576 KB |
Output is correct |
11 |
Correct |
2 ms |
576 KB |
Output is correct |
12 |
Correct |
2 ms |
576 KB |
Output is correct |
13 |
Correct |
3 ms |
632 KB |
Output is correct |
14 |
Correct |
3 ms |
632 KB |
Output is correct |
15 |
Correct |
3 ms |
632 KB |
Output is correct |
16 |
Correct |
2 ms |
632 KB |
Output is correct |
17 |
Correct |
4 ms |
632 KB |
Output is correct |
18 |
Correct |
2 ms |
648 KB |
Output is correct |
19 |
Correct |
2 ms |
648 KB |
Output is correct |
20 |
Correct |
3 ms |
648 KB |
Output is correct |
21 |
Correct |
3 ms |
648 KB |
Output is correct |
22 |
Correct |
5 ms |
676 KB |
Output is correct |
23 |
Correct |
3 ms |
676 KB |
Output is correct |
24 |
Correct |
4 ms |
688 KB |
Output is correct |
25 |
Correct |
4 ms |
700 KB |
Output is correct |
26 |
Correct |
5 ms |
716 KB |
Output is correct |
27 |
Correct |
5 ms |
716 KB |
Output is correct |
28 |
Correct |
5 ms |
752 KB |
Output is correct |
29 |
Correct |
3 ms |
752 KB |
Output is correct |
30 |
Correct |
5 ms |
760 KB |
Output is correct |
31 |
Correct |
4 ms |
772 KB |
Output is correct |
32 |
Correct |
5 ms |
860 KB |
Output is correct |
33 |
Correct |
4 ms |
860 KB |
Output is correct |
34 |
Correct |
4 ms |
860 KB |
Output is correct |
35 |
Correct |
4 ms |
860 KB |
Output is correct |
36 |
Correct |
4 ms |
860 KB |
Output is correct |
37 |
Correct |
5 ms |
860 KB |
Output is correct |
38 |
Correct |
4 ms |
860 KB |
Output is correct |
39 |
Correct |
4 ms |
868 KB |
Output is correct |
40 |
Correct |
4 ms |
880 KB |
Output is correct |
41 |
Correct |
177 ms |
4480 KB |
Output is correct |
42 |
Correct |
8 ms |
4480 KB |
Output is correct |
43 |
Correct |
47 ms |
4480 KB |
Output is correct |
44 |
Correct |
231 ms |
6928 KB |
Output is correct |
45 |
Correct |
231 ms |
7764 KB |
Output is correct |
46 |
Correct |
204 ms |
8744 KB |
Output is correct |
47 |
Correct |
201 ms |
9700 KB |
Output is correct |
48 |
Correct |
190 ms |
10220 KB |
Output is correct |
49 |
Correct |
195 ms |
11588 KB |
Output is correct |
50 |
Correct |
191 ms |
11660 KB |
Output is correct |
51 |
Correct |
218 ms |
11920 KB |
Output is correct |
52 |
Correct |
218 ms |
12652 KB |
Output is correct |
53 |
Correct |
202 ms |
12652 KB |
Output is correct |
54 |
Correct |
229 ms |
12764 KB |
Output is correct |
55 |
Correct |
239 ms |
12764 KB |
Output is correct |
56 |
Correct |
226 ms |
12764 KB |
Output is correct |
57 |
Correct |
200 ms |
12764 KB |
Output is correct |
58 |
Correct |
240 ms |
12764 KB |
Output is correct |
59 |
Correct |
215 ms |
12764 KB |
Output is correct |
60 |
Correct |
211 ms |
12844 KB |
Output is correct |
61 |
Correct |
217 ms |
12844 KB |
Output is correct |
62 |
Correct |
190 ms |
12844 KB |
Output is correct |
63 |
Correct |
200 ms |
12844 KB |
Output is correct |
64 |
Correct |
186 ms |
12844 KB |
Output is correct |
65 |
Correct |
196 ms |
12844 KB |
Output is correct |
66 |
Correct |
189 ms |
12844 KB |
Output is correct |
67 |
Correct |
182 ms |
12844 KB |
Output is correct |
68 |
Correct |
209 ms |
12844 KB |
Output is correct |
69 |
Correct |
220 ms |
12844 KB |
Output is correct |