QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#593637 | #7944. Max Minus Min | ATM12345# | WA | 7ms | 5896kb | C++17 | 1.1kb | 2024-09-27 15:14:26 | 2024-09-27 15:14:27 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define Ma 1000005
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
ll n;
ll a[Ma];
struct node{
ll w,num;
bool operator <(const node &A)const{
return w<A.w;
}
}t[Ma];
void sol()
{
cin>>n;
for (ll i=1;i<=n;i++)
cin>>a[i],t[i]={a[i],i};
sort(t+1,t+n+1);
ll l=1,r=n,ok=t[1].num,ans=t[n].w-t[1].w;
ll mi=t[n].w;
for (ll i=n;i>1;i--)
{
if (t[i].num<ok)
{
for (ll j=l;j<t[i].num;j++)
mi=min(mi,a[j]);
l=max(l,t[i].num);
}
else
{
for (ll j=t[i].num+1;j<=r;j++)
mi=min(mi,a[j]);
r=min(r,t[i].num);
}
ans=min(ans,max(t[n].w-mi,t[i].w-t[1].w));
}
l=1,r=n,ok=t[n].num;
ll ma=t[1].w;
for (ll i=1;i<n;i++)
{
if (t[i].num<ok)
{
for (ll j=l;j<t[i].num;j++)
ma=max(ma,a[j]);
l=max(l,t[i].num);
}
else
{
for (ll j=t[i].num+1;j<=r;j++)
ma=max(ma,a[j]);
r=min(r,t[i].num);
}
ans=min(ans,max(ma-t[1].w,t[n].w-t[i].w));
}
printf("%lld\n",ans);
}
int main()
{
IOS
ll tt=1;
cin>>tt;
while (tt--)
sol();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5896kb
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: 7ms
memory: 5840kb
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 3 2 0 3 2 3 1 1 2 1 3 3 2 0 1 1 2 0 3 2 2 3 2 2 2 3 3 2 2 2 2 2 2 2 2 2 3 2 1 2 1 2 2 2 1 1 4 2 0 2 2 1 1 1 2 1 2 3 2 1 2 3 2 2 1 0 2 1 2 3 2 1 2 1 3 2 1 1 2 2 2 1 3 2 1 2 3 2 1 1 2 2 3 1 1 1 2 2 1 1 3 1 2 2 2 1 2 3 2 1 2 0 3 3 1 0 0 1 2 2 3 4 2 2 2 2 1 2 4 1 1 1 3 2 2 2 1 2 3 2 2 2 2 0 3 ...
result:
wrong answer 6th numbers differ - expected: '1', found: '3'