QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#707861 | #7944. Max Minus Min | bilbo_b# | WA | 6ms | 3752kb | C++17 | 2.4kb | 2024-11-03 17:52:51 | 2024-11-03 17:52:51 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;
signed main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int t;
cin >> t;
while(t--) {
int n;
cin >> n;
vector<int> a(n);
for(auto &i : a) {
cin >> i;
}
int mx = a[0], mn = a[0], imx = 0, imn = 0;
for(int i = 1; i < n; ++i) {
if (a[i] > mx) {
mx = a[i];
imx = a[i];
}
if(a[i] < mn) {
mn = a[i];
imn = i;
}
}
int l = 0, r = mx - mn;
while(l < r) {
int c = (l + r) / 2;
bool f = false;
{
int tl = imx, tr = imx;
while(tl - 1 >= 0 && a[tl - 1] >= mx - c) {
tl -= 1;
}
while(tr + 1 < n && a[tr + 1] >= mx - c) {
tr += 1;
}
bool ok = true;
for (int i = 0; i < tl; ++i) {
if (a[i] > mn + c) {
ok = false;
break;
}
}
for (int i = tr + 1; i < n; ++i) {
if (a[i] > mn + c) {
ok = false;
break;
}
}
f = ok;
}
if(!f) {
int tl = imn, tr = imn;
while(tl - 1 >= 0 && a[tl - 1] <= mn + c) {
tl -= 1;
}
while(tr + 1 < n && a[tr + 1] <= mn + c) {
tr += 1;
}
bool ok = true;
for (int i = 0; i < tl; ++i) {
if (a[i] < mx - c) {
ok = false;
break;
}
}
for (int i = tr + 1; i < n; ++i) {
if (a[i] < mx - c) {
ok = false;
break;
}
}
f = ok;
}
if(f) {
r = c;
} else {
l = c + 1;
}
}
cout << l << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
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: 6ms
memory: 3752kb
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 4 2 0 3 1 3 2 1 4 1 2 3 2 0 1 1 1 0 3 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 2 2 2 2 2 1 2 2 3 3 2 1 1 2 1 2 3 3 0 2 1 1 2 3 1 2 2 2 1 4 2 1 2 3 2 1 1 2 2 3 1 1 1 2 2 3 1 3 1 2 2 2 2 2 3 2 1 2 0 4 1 1 1 1 1 2 3 2 2 2 2 1 2 1 2 4 1 1 1 3 2 2 1 1 3 1 2 2 2 3 1 3 ...
result:
wrong answer 6th numbers differ - expected: '1', found: '4'