#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}
// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
public:
template<typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif
// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back
// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;
// ---------- END OF TEMPLATE ----------
int X[100000];
vplli L,R;
int main() {
int i;
int N,K,T;
scanf("%d %d %d",&N,&K,&T),K--;
for (i = 0; i < N; i++) scanf("%d",&X[i]);
int s = 0,e = 1e9;
while (s < e) {
int m = (s+e) / 2;
LLI ss2 = 0;
for (i = 1; i <= K; i++) {
LLI d = 2*m-(X[i]-X[i-1]);
ss2 += d;
if (d >= 0) L.pb(mp(d,0));
else {
LLI m = d;
while (!L.empty() && (L.back().first >= 0)) {
m = min(m,d+L.back().second);
d += L.back().first;
L.pop_back();
if (d >= 0) break;
}
L.pb(mp(d,m));
}
}
for (i = N-2; i >= K; i--) {
LLI d = 2*m-(X[i+1]-X[i]);
ss2 += d;
if (d >= 0) R.pb(mp(d,0));
else {
LLI m = d;
while (!R.empty() && (R.back().first >= 0)) {
m = min(m,d+R.back().second);
d += R.back().first;
R.pop_back();
if (d >= 0) break;
}
R.pb(mp(d,m));
}
}
reverse(L.begin(),L.end());
reverse(R.begin(),R.end());
int a = 0,b = 0;
LLI ss = 0;
int f = 0;
while ((a < L.size()) || (b < R.size())) {
if ((a < L.size()) && (L[a].first >= 0) && (ss+L[a].second >= 0)) ss += L[a].first,a++;
else if ((b < R.size()) && (R[b].first >= 0) && (ss+R[b].second >= 0)) ss += R[b].first,b++;
else {
f = 1;
break;
}
}
int good = 0;
if (f) {
if (ss2 < 0) good = 0;
else {
int aa = (int) L.size()-1,bb = (int) R.size()-1;
good = 1;
while ((aa >= a) || (bb >= b)) {
if ((aa >= a) && (L[aa].first <= 0) && (ss2-L[aa].first+L[aa].second >= 0)) ss2 -= L[aa].first,aa--;
else if ((bb >= b) && (R[bb].first <= 0) && (ss2-R[bb].first+R[bb].second >= 0)) ss2 -= R[bb].first,bb--;
else {
good = 0;
break;
}
}
}
}
else {
good = ((a == L.size()) && (b == R.size()) && (ss >= 0));
if (good) assert(ss == ss2);
}
if (good) e = m;
else s = m+1;
L.clear(),R.clear();
}
printf("%d\n",(s+T-1)/T);
return 0;
}
Compilation message
sparklers.cpp: In function 'int main()':
sparklers.cpp:106:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | while ((a < L.size()) || (b < R.size())) {
| ~~^~~~~~~~~~
sparklers.cpp:106:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | while ((a < L.size()) || (b < R.size())) {
| ~~^~~~~~~~~~
sparklers.cpp:107:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
107 | if ((a < L.size()) && (L[a].first >= 0) && (ss+L[a].second >= 0)) ss += L[a].first,a++;
| ~~^~~~~~~~~~
sparklers.cpp:108:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
108 | else if ((b < R.size()) && (R[b].first >= 0) && (ss+R[b].second >= 0)) ss += R[b].first,b++;
| ~~^~~~~~~~~~
sparklers.cpp:131:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
131 | good = ((a == L.size()) && (b == R.size()) && (ss >= 0));
| ~~^~~~~~~~~~~
sparklers.cpp:131:43: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
131 | good = ((a == L.size()) && (b == R.size()) && (ss >= 0));
| ~~^~~~~~~~~~~
sparklers.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
63 | scanf("%d %d %d",&N,&K,&T),K--;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:64:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
64 | for (i = 0; i < N; i++) scanf("%d",&X[i]);
| ~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
260 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
2 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
2 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
260 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
2 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
2 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
332 KB |
Output is correct |
41 |
Correct |
25 ms |
2444 KB |
Output is correct |
42 |
Correct |
2 ms |
332 KB |
Output is correct |
43 |
Correct |
8 ms |
916 KB |
Output is correct |
44 |
Correct |
47 ms |
3908 KB |
Output is correct |
45 |
Correct |
46 ms |
4032 KB |
Output is correct |
46 |
Correct |
45 ms |
4144 KB |
Output is correct |
47 |
Correct |
44 ms |
4200 KB |
Output is correct |
48 |
Correct |
52 ms |
3788 KB |
Output is correct |
49 |
Correct |
45 ms |
3776 KB |
Output is correct |
50 |
Correct |
45 ms |
4032 KB |
Output is correct |
51 |
Correct |
45 ms |
4128 KB |
Output is correct |
52 |
Correct |
46 ms |
3784 KB |
Output is correct |
53 |
Correct |
45 ms |
3904 KB |
Output is correct |
54 |
Correct |
39 ms |
3780 KB |
Output is correct |
55 |
Correct |
45 ms |
4032 KB |
Output is correct |
56 |
Correct |
46 ms |
4008 KB |
Output is correct |
57 |
Correct |
45 ms |
3776 KB |
Output is correct |
58 |
Correct |
44 ms |
3804 KB |
Output is correct |
59 |
Correct |
31 ms |
3292 KB |
Output is correct |
60 |
Correct |
34 ms |
3776 KB |
Output is correct |
61 |
Correct |
33 ms |
3648 KB |
Output is correct |
62 |
Correct |
34 ms |
4032 KB |
Output is correct |
63 |
Correct |
34 ms |
3760 KB |
Output is correct |
64 |
Correct |
33 ms |
4204 KB |
Output is correct |
65 |
Correct |
34 ms |
3776 KB |
Output is correct |
66 |
Correct |
34 ms |
3912 KB |
Output is correct |
67 |
Correct |
33 ms |
3648 KB |
Output is correct |
68 |
Correct |
34 ms |
3796 KB |
Output is correct |
69 |
Correct |
34 ms |
3804 KB |
Output is correct |