QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#876740 | #7944. Max Minus Min | tassei903# | WA | 7ms | 3712kb | C++23 | 2.2kb | 2025-01-31 12:15:23 | 2025-01-31 12:15:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define ov4(a, b, c, d, name, ...) name
#define rep3(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep2(i, a, b) rep3(i, a, b, 1)
#define rep1(i, n) rep2(i, 0, n)
#define rep0(n) rep1(aaaaa, n)
#define rep(...) ov4(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__)
#define per(i, a, b) for(ll i = (a)-1; i >= (b); i--)
#define fore(e, v) for(auto&& e : v)
#define all(a) begin(a), end(a)
#define sz(a) (int)(size(a))
#define lb(v, x) (lower_bound(all(v), x) - begin(v))
#define eb emplace_back
template<typename T, typename S> bool chmin(T& a, const S& b) { return a > b ? a = b, 1 : 0; }
template<typename T, typename S> bool chmax(T& a, const S& b) { return a < b ? a = b, 1 : 0; }
const int INF = 1e9 + 100;
const ll INFL = 3e18 + 100;
#define i128 __int128_t
struct _ {
_() { cin.tie(0)->sync_with_stdio(0), cout.tie(0); }
} __;
const int m = 20;
void solve() {
int n;cin >> n;
vl a(n);rep(i, n) cin >> a[i];
ll l = *min_element(all(a)), r = *max_element(all(a));
auto check = [&](ll M) -> bool {
if (r - l <= M) return true;
ll d = r - l - M;
int L = 1e9, R = -1;
rep(i, n) {
if (a[i] > l + M) {
L = min(L, (int)i);
R = max(R, (int)i);
}
}
bool FLAG = 1;
rep(i, L, R) {
if (a[i] - d < l) FLAG = 0;
}
if (FLAG) return true;
L = 1e9, R = -1;
rep(i, n) {
if (a[i] < r - M) {
L = min(L, (int)i);
R = max(R, (int)i);
}
}
FLAG = 1;
rep(i, L, R) {
if (a[i] + d > r) FLAG = 0;
}
if (FLAG) return true;
return false;
};
ll ok = 1e9 + 10, ng = -1;
while (ok - ng > 1) {
ll mid = (ok + ng) / 2;
if (check(mid)) ok = mid;
else ng = mid;
}
cout << ok << endl;
}
int main() {
int T;cin >> T;
// int T = 1;
while (T--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3712kb
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 1 1 2 0 3 2 3 1 1 2 1 2 3 2 0 1 1 1 0 3 2 2 3 2 2 2 3 3 2 2 1 2 1 2 2 2 2 0 2 1 2 1 2 2 2 1 1 2 2 1 2 2 1 0 1 2 1 2 2 1 1 2 3 2 2 0 0 2 1 2 3 2 0 2 0 1 2 1 0 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 3 2 1 2 0 1 1 1 0 0 1 2 2 2 2 2 2 1 2 1 1 4 1 1 1 3 2 2 1 0 2 1 2 1 2 2 1 3 ...
result:
wrong answer 22nd numbers differ - expected: '2', found: '1'