/*input
3 2 50
0
200
300
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
out<<'('<<P.F<<','<<P.S<<')';
return out;
}
//}}}
const ll maxn=1005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;
ll mypow(ll a,ll b){
ll res=1LL;
while(b){
if(b&1) res=res*a%MOD;
a=a*a%MOD;
b>>=1;
}
return res;
}
int n,k;
ll t;
ll a[maxn];
vector<ll> A,B;
vector<pll> C,D;
int main(){
__int128 meow=0;
IOS;
cin>>n>>k>>t;
k--;
REP(i,n) cin>>a[i];
ll l=-1,r=1000000000LL;
while(l!=r-1){
ll mid=(l+r)/2;
// cout<<mid<<'\n';
A.clear();
B.clear();
for(int i=k-1;i>=0;i--){
A.pb(a[i+1]-a[i]-mid*t*2);
}
for(int i=k;i<n-1;i++){
B.pb(a[i+1]-a[i]-mid*t*2);
}
C.clear();D.clear();
{
ll pos=0,neg=0;
for(int i=0;i<SZ(A);i++){
if(i&&A[i]>=0&&A[i-1]<0){
C.pb(pos,neg);
pos=0,neg=0;
}
if(A[i]>=0) pos+=A[i];
else neg-=A[i];
}
C.pb(pos,neg);
}
{
ll pos=0,neg=0;
for(int i=0;i<SZ(B);i++){
if(i&&B[i]>=0&&B[i-1]<0){
D.pb(pos,neg);
pos=0,neg=0;
}
if(B[i]>=0) pos+=B[i];
else neg-=B[i];
}
D.pb(pos,neg);
}
// for(auto i:C) cout<<i<<' ';
// cout<<'\n';
// for(auto i:D) cout<<i<<' ';
// cout<<'\n';
ll pt=0;
int i=0,j=0;
bool f=1;
while(i<SZ(C)||j<SZ(D)){
if(i==SZ(C)){
pt+=D[j].F;
if(pt>0){
f=0;
break;
}
pt-=D[j].S;
j++;
}
else if(j==SZ(D)){
pt+=C[i].F;
if(pt>0){
f=0;
break;
}
pt-=C[i].S;
i++;
}
else if(pt+C[i].F>0){
pt+=D[j].F;
if(pt>0){
f=0;
break;
}
pt-=D[j].S;
j++;
}
else if(pt+D[j].F>0){
pt+=C[i].F;
if(pt>0){
f=0;
break;
}
pt-=C[i].S;
i++;
}
else{
if(C[i].F<=C[i].S){
pt+=C[i].F-C[i].S;
i++;
}
else if(D[j].F<=D[j].S){
pt+=D[j].F-D[j].S;
j++;
}
else{
if(C[i].S>D[j].S){
pt+=C[i].F-C[i].S;
i++;
}
else{
pt+=D[j].F-D[j].S;
j++;
}
}
}
}
if(f) r=mid;
else l=mid;
}
cout<<r<<'\n';
return 0;
}
Compilation message
sparklers.cpp: In function 'int main()':
sparklers.cpp:61:11: warning: unused variable 'meow' [-Wunused-variable]
__int128 meow=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 |
380 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 |
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 |
380 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 |
# |
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 |
380 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 |
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 |
380 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 |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
28 |
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 |
380 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 |
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 |
380 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 |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |