#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];
pll solve(vector<lint> &v, vector<pll> &r) {
pll x = pll(0, 0);
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();
}
if(t.fi >= 0) r.push_back(t);
else {
x.se = max(t.se, x.se - t.fi);
x.fi += t.fi;
}
}
return x;
}
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]);
lint sum = 0;
vector<pll> r1, r2;
pll x1 = solve(v1, r1);
pll x2 = solve(v2, r2);
/*
printf("m = %lld\nv1 : ", m);
for(auto a : v1) printf("%lld ", a);
printf("\nv2 : ");
for(auto a : v2) printf("%lld ", a);
printf("\nr1 : ");
for(auto a : r1) printf("(%lld, %lld) ", a.fi, a.se);
printf("\nr2 : ");
for(auto a : r2) printf("(%lld, %lld) ", a.fi, a.se);
printf("\n");
*/
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;
else if(t >= x1.se && t >= x2.se && t >= min(x1.se - x2.fi, x2.se - x1.fi))
e = m;
else s = m + 1;
}
cout << s << "\n";
return 0;
}
Compilation message
sparklers.cpp: In function 'int main()':
sparklers.cpp:47:8: warning: unused variable 'sum' [-Wunused-variable]
lint sum = 0;
^~~
# |
Verdict |
Execution time |
Memory |
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 |
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 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |