#include <bits/stdc++.h>
#define lld long long
#define pii pair<int,int>
#define pll pair<lld,lld>
#define pb push_back
#define next nextt
#define left leftt
#define right rightt
#define Inf 1000000000
#define Linf 1000000000000000000LL
#define Mod 1000000007
using namespace std;
int N,M,ans; lld T;
lld a[100002];
bool can(lld X){
X *= T; X %= Mod;
int l,r,cnt;
lld s,e;
l = r = M; cnt = 1;
s = e = a[M];
bool bef1,bef2,flag1,flag2;
while(r-l != N-1){
bef1 = flag1; bef2 = flag2; flag1 = flag2 = false;
if(r != N && max(s-X,a[r+1]-X*cnt) <= min(e+X,a[r+1]+X*cnt)) flag2 = true;
if(l != 1 && max(s-X,a[l-1]-X*cnt) <= min(e+X,a[l-1]+X*cnt)){
s = max(s-X,a[l-1]-X*cnt);
e = min(e+X,a[l-1]+X*cnt);
l--;
flag1 = true;
}else if(r != N && max(s-X,a[r+1]-X*cnt) <= min(e+X,a[r+1]+X*cnt)){
s = max(s-X,a[r+1]-X*cnt);
e = min(e+X,a[r+1]+X*cnt);
r++;
}else return false;
s = max((lld)0,s); e = min(e,(lld)Mod);
cnt++;
if(r-l != 1 && (bef1 && bef2 && !flag2)){
while(true);
}
}
return true;
}
int main(){
//freopen("input.txt","r",stdin);
scanf("%d %d %lld",&N,&M,&T);
for(int i=1; i<=N; i++){
scanf("%lld",&a[i]);
}
int l,r;
l = 0; r = a[N];
while(l <= r){
int m = (l+r)/2;
if(can(m)){
ans = m;
r = m-1;
}else l = m+1;
}
printf("%d\n",ans);
return 0;
}
Compilation message
sparklers.cpp: In function 'int main()':
sparklers.cpp:54:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %lld",&N,&M,&T);
^
sparklers.cpp:56:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&a[i]);
^
sparklers.cpp: In function 'bool can(long long int)':
sparklers.cpp:44:24: warning: 'flag2' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(r-l != 1 && (bef1 && bef2 && !flag2)){
^
sparklers.cpp:44:24: warning: 'flag1' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2800 KB |
Output is correct |
2 |
Correct |
0 ms |
2800 KB |
Output is correct |
3 |
Correct |
0 ms |
2800 KB |
Output is correct |
4 |
Correct |
0 ms |
2800 KB |
Output is correct |
5 |
Correct |
0 ms |
2800 KB |
Output is correct |
6 |
Correct |
0 ms |
2800 KB |
Output is correct |
7 |
Incorrect |
0 ms |
2800 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2800 KB |
Output is correct |
2 |
Correct |
0 ms |
2800 KB |
Output is correct |
3 |
Correct |
0 ms |
2800 KB |
Output is correct |
4 |
Correct |
0 ms |
2800 KB |
Output is correct |
5 |
Correct |
0 ms |
2800 KB |
Output is correct |
6 |
Correct |
0 ms |
2800 KB |
Output is correct |
7 |
Incorrect |
0 ms |
2800 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2800 KB |
Output is correct |
2 |
Correct |
0 ms |
2800 KB |
Output is correct |
3 |
Correct |
0 ms |
2800 KB |
Output is correct |
4 |
Correct |
0 ms |
2800 KB |
Output is correct |
5 |
Correct |
0 ms |
2800 KB |
Output is correct |
6 |
Correct |
0 ms |
2800 KB |
Output is correct |
7 |
Incorrect |
0 ms |
2800 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |