QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#337148 | #7944. Max Minus Min | Days_of_Future_Past# | WA | 14ms | 3924kb | C++14 | 1.3kb | 2024-02-25 06:42:01 | 2024-02-25 06:42:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const int N = 200022;
int a[N];
void solve() {
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int mx = *max_element(a, a + n);
int mn = *min_element(a, a + n);
int le = 0, ri = inf;
while(le != ri) {
int mid = (le + ri) / 2;
bool ok = false;
for(int d = 0; d < 2; d++) {
int st = n, ed = -1, cnt = 0;
bool flag = true;
for(int i = 0; i < n; i++) {
if(a[i] < mx - mid) {
st = min(st, i);
ed = max(ed, i);
cnt++;
if(a[i] + (mx - mid - mn) > mx) {
flag = false;
}
}
}
if(flag) {
ok |= cnt == 0 || (ed - st + 1) == cnt;
}
for(int i = 0; i < n; i++) {
a[i] = -a[i];
}
swap(mn, mx);
mx = -mx;
mn = -mn;
}
if(ok) {
ri = mid;
} else {
le = mid + 1;
}
}
printf("%d\n", le);
}
int main() {
int t;
scanf("%d", &t);
for(int qq = 1; qq <= t; qq++) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3924kb
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: 14ms
memory: 3908kb
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 1 3 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 4 2 1 2 2 1 1 1 2 1 2 3 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 2 3 1 1 1 2 2 1 1 1 1 2 2 2 2 2 4 2 1 2 0 1 1 1 1 1 1 2 2 3 4 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 16th numbers differ - expected: '2', found: '3'