QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#693857 | #7944. Max Minus Min | kzxx00011 | WA | 16ms | 3684kb | C++14 | 876b | 2024-10-31 16:51:25 | 2024-10-31 16:51:26 |
Judging History
answer
#include<iostream>
using namespace std;
const int N=2e5+10;
int t,n;
int a[N];
int maxx,minn;
int ans=0;
bool check(int x) //能否把最大值下降x点距离
{
//if(x==0) return 1;
//cout<<x<<endl;
int lj=2e5+10,rj=0;
//int lb=2e5+10,rb=0;
for(int i=1;i<=n;i++)
{
if(a[i]>maxx-x) //需要下降
{
rj=max(rj,i);
lj=min(lj,i);
}
}
for(int i=1;i<=n;i++)
{
if(a[i]<minn+x) //不能下降
{
if(i>=lj&&i<=rj) return 0;
}
}
return 1;
}
int main()
{
cin>>t;
while(t--)
{
cin>>n;
maxx=0,minn=1e9+10;
for(int i=1;i<=n;i++)
{
cin>>a[i];
maxx=max(maxx,a[i]);
minn=min(minn,a[i]);
}
int l=0,r=maxx-minn;
ans=0;
while(l<=r)
{
int mid=(l+r)/2;
if(check(mid))
{
ans=mid;
l=mid+1;
}
else r=mid-1;
}
cout<<maxx-minn-ans<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
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: 16ms
memory: 3684kb
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 3 1 1 2 1 3 2 3 1 1 2 3 2 3 2 0 1 2 2 0 3 2 2 3 3 2 2 3 4 3 2 3 2 2 2 2 2 2 4 2 1 2 1 3 4 3 1 3 2 2 4 3 2 1 1 1 2 1 2 3 1 4 4 3 2 2 1 1 2 1 3 3 2 1 2 1 1 2 1 1 2 2 2 1 3 2 2 4 3 2 1 1 3 2 4 1 1 1 2 2 1 1 1 1 2 4 2 2 2 3 3 2 2 3 1 3 1 1 1 1 2 2 2 2 2 2 1 2 1 2 4 1 2 1 3 2 2 2 1 2 1 2 1 2 2 2 4 ...
result:
wrong answer 8th numbers differ - expected: '0', found: '1'