QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#725027#7944. Max Minus MinMinaseAyano_qwqWA 9ms3908kbC++14925b2024-11-08 15:56:442024-11-08 15:56:49

Judging History

你现在查看的是最新测评结果

  • [2024-11-08 15:56:49]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:3908kb
  • [2024-11-08 15:56:44]
  • 提交

answer

#include<iostream>
using namespace std;
const int N=2e5+10;
int n,a[N],mx,mi;
bool check1(int x){
	int l=mi,r=mi;
	while(l-1>0&&a[l-1]>=a[mx]-x) l--;
	while(r+1<=n&&a[r+1]>=a[mx]-x) r++;
	for(int i=1;i<l;i++) if(a[i]>a[mi]+x) return 0;
	for(int i=r+1;i<=n;i++) if(a[i]>a[mi]+x) return 0;
	return 1;
}
bool check2(int x){
	int l=mi,r=mi;
	while(l-1>0&&a[l-1]<=a[mi]+x) l--;
	while(r+1<=n&&a[r+1]<=a[mi]+x) r++;
	for(int i=1;i<l;i++) if(a[i]<a[mx]-x) return 0;
	for(int i=r+1;i<=n;i++) if(a[i]<a[mx]-x) return 0;
	return 1;	
}
int solve(){
	mx=0,mi=n+1,a[n+1]=1e9;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		if(a[i]>a[mx]) mx=i;
		if(a[i]<a[mi]) mi=i;
	} 
	int l=0,r=a[mx]-a[mi],mid;
	while(l<=r){
		mid=(l+r)/2;
		if(check1(mid)||check2(mid)) r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",l);
	return 0;
}
int main(){
	int T;
	cin>>T;
	while(T--) solve();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3908kb

input:

4
3
42 42 42
4
1 2 2 1
5
1 100 1 100 1
6
1 2 3 4 5 6

output:

0
0
99
2

result:

ok 4 number(s): "0 0 99 2"

Test #2:

score: -100
Wrong Answer
time: 9ms
memory: 3808kb

input:

19530
6
2 3 3 3 4 3
6
2 4 4 2 5 5
6
2 5 2 5 1 3
6
4 4 1 2 4 1
5
5 4 5 3 3
5
2 2 1 5 1
6
3 1 2 4 2 3
5
5 5 4 4 5
6
5 3 3 1 4 2
6
3 3 2 4 2 4
6
1 2 4 5 2 5
5
3 4 5 5 3
6
4 3 3 3 4 3
6
1 5 1 2 3 1
5
5 5 2 1 4
6
1 2 5 3 5 2
6
4 5 2 4 5 2
5
2 4 2 4 1
4
2 3 3 3
6
1 2 2 1 4 5
6
3 2 1 3 3 2
6
2 1 1 2 5 3
6
...

output:

1
2
3
2
1
1
2
0
2
2
3
1
1
2
1
3
1
2
0
1
1
2
0
2
2
1
3
2
2
2
3
1
2
2
1
3
2
2
2
3
2
1
2
1
2
1
2
2
2
1
1
2
1
1
1
2
1
1
1
2
1
1
2
1
2
2
3
2
2
1
1
2
1
2
3
2
0
2
1
1
2
1
1
2
2
2
1
3
2
1
2
3
2
1
1
2
2
3
1
2
1
2
2
1
1
1
1
2
2
2
2
2
3
2
1
2
0
1
1
1
1
1
1
2
2
2
2
1
2
2
1
1
2
4
1
1
1
2
2
3
2
1
2
3
2
2
2
2
1
3
...

result:

wrong answer 4th numbers differ - expected: '3', found: '2'