QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#587780 | #7944. Max Minus Min | eroinevs | WA | 19ms | 3840kb | C++14 | 2.3kb | 2024-09-24 21:38:33 | 2024-09-24 21:38:39 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define ff first
#define ss second
#define PI pair<int, int>
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define bust ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int INF = (int)1e9 + 7;
void solve(){
int n;
cin >> n;
ll a[n];
ll mx = 0, mxi = 0, mn = INF, mni = 0;
for(int i = 0; i < n; ++i){
cin >> a[i];
if(a[i] > mx){
mx = a[i];
mxi = i;
}
if(a[i] < mn){
mn = a[i];
mni = i;
}
}
ll l = -1, r = mx+1000;
while(l < r - 1){
ll mid = (l + r)/2;
vector<bool> used(n, false);
int li = mni;
while(li >= 0 && a[li] <= mn + mid){
used[li] = 1;
++li;
}
int ri = mni;
while(ri < n && a[ri] <= mn + mid){
used[ri] = 1;
++ri;
}
bool f = 0;
ll mx2 = 0, mn2 = INF;
for(int i = 0; i < n; ++i){
if(used[i]) continue;
mx2 = max(mx2, a[i]);
mn2 = min(mn2, a[i]);
}
if(mx2-mn2 > mid){
l = mid;
}
else{
r = mid;
}
// cout << l << " " << r << '\n';
}
// cout << r << '\n';
ll l2 = -1, r2 = mx+1000;
while(l2 < r2 - 1){
ll mid = (l2 + r2)/2;
vector<bool> used(n, false);
int li = mxi;
while(li >= 0 && a[li] >= mx - mid){
used[li] = 1;
--li;
}
int ri = mxi;
while(ri < n && a[ri] >= mx - mid){
used[ri] = 1;
++ri;
}
bool f = 0;
ll mx2 = 0, mn2 = INF;
for(int i = 0; i < n; ++i){
if(used[i]) continue;
mx2 = max(mx2, a[i]);
mn2 = min(mn2, a[i]);
}
if(mx2-mn2 > mid){
l2 = mid;
}
else{
r2 = mid;
}
// cout << l2 << " " << r2 << '\n';
}
// cout << r2 << '\n';
ll ans = min(r, r2);
cout << ans << '\n';
}
signed main() {
bust
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
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: 19ms
memory: 3840kb
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 0 3 2 3 1 1 2 3 2 3 2 0 1 1 2 0 3 2 2 3 2 2 2 3 3 2 2 1 2 2 2 2 2 2 1 2 1 2 1 3 2 2 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 3 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 1 1 2 2 1 1 1 1 2 3 2 2 2 3 3 1 2 0 1 3 1 1 1 1 2 2 2 2 2 2 1 2 1 2 4 1 1 1 3 2 2 2 1 2 1 2 1 2 2 1 3 ...
result:
wrong answer 15th numbers differ - expected: '1', found: '3'