QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#878669 | #7944. Max Minus Min | fractal# | WA | 7ms | 3584kb | C++17 | 1.6kb | 2025-02-01 16:38:35 | 2025-02-01 16:38:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
const int N = 2e5 + 200;
int n, a[N];
long long get() {
int mx = *max_element(a + 1, a + n + 1);
int mn = *min_element(a + 1, a + n + 1);
long long ans = mx - mn;
long long tl = 0, tr = ans;
while (tl <= tr) {
long long d = tl + tr >> 1;
int lmn = n + 1, rmn = 0;
for (int i = 1; i <= n; ++i) {
if (a[i] < mx - d) {
lmn = min(i, lmn);
rmn = max(i, rmn);
}
}
if (lmn > rmn) {
ans = min(ans, d);
tr = d - 1;
continue;
}
int mx2 = -1e9;
for (int i = lmn; i <= rmn; ++i) {
mx2 = max(mx2, a[i]);
}
int x = mx - mx2;
for (int i = lmn; i <= rmn; ++i) {
a[i] += x;
}
long long kek = *max_element(a + 1, a + n + 1) - *min_element(a + 1, a + n + 1);
if (kek <= d) {
ans = min(ans, kek);
tr = d - 1;
}
else {
tl = d + 1;
}
}
return ans;
}
void solve() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
long long ans = get();
for (int i = 1; i <= n; ++i) {
a[i] = (int)1e9 - a[i];
}
ans = min(ans, get());
cout << ans << '\n';
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int T;
cin >> T;
while (T--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
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: 3584kb
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 0 0 2 0 3 2 3 0 1 1 0 3 3 2 0 1 1 1 0 3 2 2 3 1 2 2 3 1 1 2 1 1 1 1 2 3 2 0 1 0 2 1 0 1 2 1 0 2 2 0 0 2 1 0 0 2 1 2 1 1 1 0 3 2 2 0 0 0 1 2 2 1 0 2 0 0 2 0 0 1 1 1 1 3 2 0 1 3 1 0 1 0 2 2 1 2 0 2 2 1 0 1 0 2 1 2 1 1 3 0 0 1 0 0 0 1 0 0 0 2 0 2 2 2 2 2 2 0 1 4 1 0 1 1 1 2 1 0 2 0 1 2 2 1 0 3 ...
result:
wrong answer 5th numbers differ - expected: '1', found: '0'