#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<lint, lint> pll;
#define fi first
#define se second
const int MAXN = 100010;
const int INF = 1 << 30;
lint X[MAXN];
void solve(vector<lint> &v, vector<pll> &r, vector<pll> &x) {
for(auto &a : v) {
pll t = pll(a, max(-a, 0ll));
while(!r.empty() && t.fi < 0) {
t.se = max(t.se, r.back().se - t.fi);
t.fi += r.back().fi;
r.pop_back();
}
(t.fi >= 0 ? r : x).push_back(t);
}
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int N, K;
lint T;
cin >> N >> K >> T;
for(int i = 1; i <= N; i++) cin >> X[i];
lint s = 0, e = INF;
while(s < e) {
lint m = (s + e) / 2;
vector<lint> v1, v2;
for(int i = 1; i < K; i++) v1.push_back(2 * T * m - X[i + 1] + X[i]);
for(int i = N; i > K; i--) v2.push_back(2 * T * m - X[i] + X[i - 1]);
vector<pll> r1, r2, x1, x2;
solve(v1, r1, x1);
solve(v2, r2, x2);
lint t = 0;
int p1 = int(r1.size()) - 1, p2 = int(r2.size()) - 1;
while(p1 >= 0 || p2 >= 0) {
if(p1 >= 0 && t >= r1[p1].se) t += r1[p1--].fi;
else if(p2 >= 0 && t >= r2[p2].se) t += r2[p2--].fi;
else break;
}
if(p1 >= 0 || p2 >= 0) {
s = m + 1;
continue;
}
p1 = p2 = 0;
t = 0;
for(auto a : v1) t += a;
for(auto a : v2) t += a;
while(p1 < x1.size() || p2 < x2.size()) {
if(p1 < x1.size() && t - x1[p1].fi >= x1[p1].se) t -= x1[p1++].fi;
else if(p2 < x2.size() && t - x2[p2].fi >= x2[p2].se) t -= x2[p2++].fi;
else break;
}
if(p1 < x1.size() || p2 < x2.size()) s = m + 1;
else e = m;
}
cout << s << "\n";
return 0;
}
Compilation message
sparklers.cpp: In function 'int main()':
sparklers.cpp:60:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(p1 < x1.size() || p2 < x2.size()) {
~~~^~~~~~~~~~~
sparklers.cpp:60:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(p1 < x1.size() || p2 < x2.size()) {
~~~^~~~~~~~~~~
sparklers.cpp:61:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(p1 < x1.size() && t - x1[p1].fi >= x1[p1].se) t -= x1[p1++].fi;
~~~^~~~~~~~~~~
sparklers.cpp:62:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
else if(p2 < x2.size() && t - x2[p2].fi >= x2[p2].se) t -= x2[p2++].fi;
~~~^~~~~~~~~~~
sparklers.cpp:65:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(p1 < x1.size() || p2 < x2.size()) s = m + 1;
~~~^~~~~~~~~~~
sparklers.cpp:65:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(p1 < x1.size() || p2 < x2.size()) s = m + 1;
~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 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 |
380 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 |
2 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 |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 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 |
376 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 |
380 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 |
2 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 |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
3 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
29 |
Correct |
3 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
376 KB |
Output is correct |
31 |
Correct |
3 ms |
376 KB |
Output is correct |
32 |
Correct |
3 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 |
3 ms |
376 KB |
Output is correct |
36 |
Correct |
3 ms |
380 KB |
Output is correct |
37 |
Correct |
3 ms |
376 KB |
Output is correct |
38 |
Correct |
3 ms |
376 KB |
Output is correct |
39 |
Correct |
3 ms |
376 KB |
Output is correct |
40 |
Correct |
3 ms |
376 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 |
376 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 |
380 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 |
2 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 |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
3 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
376 KB |
Output is correct |
29 |
Correct |
3 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
376 KB |
Output is correct |
31 |
Correct |
3 ms |
376 KB |
Output is correct |
32 |
Correct |
3 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 |
3 ms |
376 KB |
Output is correct |
36 |
Correct |
3 ms |
380 KB |
Output is correct |
37 |
Correct |
3 ms |
376 KB |
Output is correct |
38 |
Correct |
3 ms |
376 KB |
Output is correct |
39 |
Correct |
3 ms |
376 KB |
Output is correct |
40 |
Correct |
3 ms |
376 KB |
Output is correct |
41 |
Correct |
82 ms |
4044 KB |
Output is correct |
42 |
Correct |
5 ms |
564 KB |
Output is correct |
43 |
Correct |
21 ms |
1340 KB |
Output is correct |
44 |
Correct |
123 ms |
7012 KB |
Output is correct |
45 |
Correct |
97 ms |
5508 KB |
Output is correct |
46 |
Correct |
115 ms |
6708 KB |
Output is correct |
47 |
Correct |
116 ms |
6516 KB |
Output is correct |
48 |
Correct |
98 ms |
5548 KB |
Output is correct |
49 |
Correct |
125 ms |
7068 KB |
Output is correct |
50 |
Correct |
98 ms |
5508 KB |
Output is correct |
51 |
Correct |
117 ms |
6784 KB |
Output is correct |
52 |
Correct |
118 ms |
6576 KB |
Output is correct |
53 |
Correct |
121 ms |
7044 KB |
Output is correct |
54 |
Correct |
119 ms |
6616 KB |
Output is correct |
55 |
Correct |
103 ms |
5544 KB |
Output is correct |
56 |
Correct |
116 ms |
6896 KB |
Output is correct |
57 |
Correct |
119 ms |
6872 KB |
Output is correct |
58 |
Correct |
106 ms |
5540 KB |
Output is correct |
59 |
Correct |
103 ms |
4748 KB |
Output is correct |
60 |
Correct |
109 ms |
6576 KB |
Output is correct |
61 |
Correct |
121 ms |
6512 KB |
Output is correct |
62 |
Correct |
107 ms |
6852 KB |
Output is correct |
63 |
Correct |
104 ms |
6432 KB |
Output is correct |
64 |
Correct |
89 ms |
5500 KB |
Output is correct |
65 |
Correct |
90 ms |
5616 KB |
Output is correct |
66 |
Correct |
91 ms |
5488 KB |
Output is correct |
67 |
Correct |
88 ms |
5524 KB |
Output is correct |
68 |
Correct |
108 ms |
6488 KB |
Output is correct |
69 |
Correct |
110 ms |
6552 KB |
Output is correct |