QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#363668 | #7944. Max Minus Min | jxu# | WA | 0ms | 3776kb | C++17 | 2.5kb | 2024-03-24 01:40:34 | 2024-03-24 01:40:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vld;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<bool> vb;
typedef tuple<int,int,int> ti;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vi> vii;
typedef vector<vii> viii;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, a, b) for (int i=a; i<(b); i++)
#define FOR(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(x,A) for (auto& x : A)
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ins insert
const int MOD = 1000000007;
const char nl = '\n';
pi minmax(vi &arr, int low, int high) {
int mn = arr[low];
int mx = arr[high];
rep(i, low, high + 1) {
mn = min(arr[i], mn);
mx = max(arr[i], mx);
}
return mp(mn, mx);
}
int diff(pi &a, pi &b) {
int ans = max(b.second - a.first, a.second - b.first);
return ans;
}
bool check(vi &arr, int gap) {
int low = arr[0];
int high = arr[0];
vpi intervals;
for (int x: arr) {
if (x - low > gap || high - x > gap) {
intervals.pb({low, high});
low = x;
high = x;
}
low = min(low, x);
high = max(high, x);
}
intervals.pb({low, high});
return sz(intervals) <= 2;
}
int solve(int tt) {
int n; cin >> n;
vi arr(n);
trav(x, arr) cin >> x;
pi cur = minmax(arr, 0, n - 1);
int ans = cur.second - cur.first;
int low = 0;
int high = ans;
while(low <= high) {
int mid = (high + low)/2;
if (check(arr, mid)) {
ans = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
cout << ans << nl;
tt++;
return 0;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int T = 1;
cin >> T;
for (int i = 1; i <= T; i++) {
if (solve(i)) break;
}
T++;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3776kb
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 1 99 2
result:
wrong answer 2nd numbers differ - expected: '0', found: '1'