QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#443985 | #7944. Max Minus Min | zpy12345 | WA | 20ms | 3620kb | C++14 | 1011b | 2024-06-15 17:00:03 | 2024-06-15 17:00:04 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,a[N],max1,min1;
bool check(int d)
{
if(d==0) return 1;
bool flag1=0,flag2=0,flag11=0,flag22=0;
for(int i=1;i<=n;i++)
{
if(a[i]>max1-d&&a[i]-d<min1) return 0;
if(a[i]-d<min1)
{
if(flag1==0) flag1=1;
else if(i!=1&&a[i-1]>max1-d)
{
if(flag11==0) flag11=1;
else return 0;
}
}
if(a[i]>max1-d)
{
if(flag2==0) flag2=1;
else if(i!=1&&a[i-1]-d<min1)
{
if(flag22==0) flag22=1;
else return 0;
}
}
// cout<<flag1<<" "<<flag2<<"\n";
}
if(flag11&&flag22) return 0;
return 1;
}
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n;
int ans=0;
min1=1e9,max1=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
min1=min(min1,a[i]);
max1=max(max1,a[i]);
}
// check(1);
// return 0;
int l=0,r=max1-min1;
while(l<=r)
{
int mid=(l+r)/2;
if(check(mid))
{
ans=mid;
l=mid+1;
}
else r=mid-1;
}
// cout<<ans<<"\n";
cout<<max1-min1-ans<<'\n';
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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: 20ms
memory: 3620kb
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 3 2 3 1 1 2 1 2 2 2 0 1 1 2 0 2 2 2 3 2 2 2 3 3 2 2 1 2 2 2 2 2 2 1 2 1 2 1 2 2 2 1 1 2 2 1 2 2 1 1 1 2 1 2 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 1 2 1 1 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 1 2 1 2 3 1 1 1 2 2 2 2 1 2 1 2 1 2 2 1 3 ...
result:
wrong answer 4th numbers differ - expected: '3', found: '2'