#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]);
if (d >= 0) L.pb(mp(d,d));
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));
}
ss2 += d;
}
for (i = N-2; i >= K; i--) {
LLI d = 2*m-(X[i+1]-X[i]);
if (d >= 0) R.pb(mp(d,d));
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));
}
ss2 += d;
}
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 {
if (a == L.size()) {
if (ss+R[b].second < 0) break;
else ss += R[b].first,b++;
}
else if (b == R.size()) {
if (ss+L[a].second < 0) break;
else ss += L[a].first,a++;
}
else {
if (ss+L[a].second < 0) {
if (ss+R[b].second < 0) break;
else ss += R[b].first,b++;
}
else if (ss+R[b].second < 0) {
if (ss+L[a].second < 0) break;
else ss += L[a].first,a++;
}
else {
f = 1;
break;
}
}
}
if (ss < 0) break;
}
int good = 0;
if (f) {
if (ss2 < 0) good = 0;
else {
int aa = L.size()-1,bb = 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) && (L[bb].first < 0) && (ss2-L[bb].first+L[bb].second >= 0)) ss2 -= L[bb].first,bb--;
else {
good = 0;
break;
}
}
}
}
else good = ((a == L.size()) && (b == R.size()) && (ss >= 0));
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:110:23: 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]
110 | if (a == L.size()) {
| ~~^~~~~~~~~~~
sparklers.cpp:114:28: 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]
114 | else if (b == R.size()) {
| ~~^~~~~~~~~~~
sparklers.cpp:151: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]
151 | else good = ((a == L.size()) && (b == R.size()) && (ss >= 0));
| ~~^~~~~~~~~~~
sparklers.cpp:151:44: 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]
151 | else 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 |
208 KB |
Output is correct |
7 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
208 KB |
Output is correct |
7 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
208 KB |
Output is correct |
7 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |