QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#373163 | #7944. Max Minus Min | mcrash9# | WA | 1ms | 3560kb | C++20 | 2.1kb | 2024-04-01 04:55:04 | 2024-04-01 04:55:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n ;
int run(vector<int> a){
int n = a.size();
int m = 0;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
for(int j = 0 ; j < n; j++){
pq.push(make_pair(a[j], j));
m = max(a[j], m);
}
pq.push(make_pair(INT_MAX, 0));
pair<int, int> f = pq.top();
pq.pop();
int l, r;
l = r = f.second;
int biggestIn = f.first;
int smallestIn = f.first;
int val = f.first;
int ans = m - smallestIn;
while(!pq.empty()){
while(pq.top().first == val){
pair<int, int> curr = pq.top();
pq.pop();
for(int j = l ; j >= curr.second; j--){
biggestIn = max(biggestIn, a[j]);
}
for(int j = r; j <= curr.second; j++){
biggestIn = max(biggestIn, a[j]);
}
l = min(l, curr.second);
r = max(r, curr.second);
}
if(pq.top().first == INT_MAX){
break;
}
int pos = max(biggestIn - smallestIn, m - pq.top().first);
ans = min(pos, ans);
pair<int, int> curr = pq.top();
pq.pop();
for(int j = l ; j >= curr.second; j--){
biggestIn = max(biggestIn, a[j]);
}
for(int j = r; j <= curr.second; j++){
biggestIn = max(biggestIn, a[j]);
}
l = min(l, curr.second);
r = max(r, curr.second);
val = curr.first;
}
return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
vector<int> a(n, 0);
for(int j = 0 ; j < n; j++){
cin >> a[j];
}
int ans = run(a);
for(int j = 0 ; j < n; j++){
a[j] = -a[j];
}
ans = min(ans, run(a));
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3560kb
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
result:
wrong answer Answer contains longer sequence [length = 4], but output contains 1 elements