# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199798 | zoooma13 | Pismo (COCI18_pismo) | C++14 | 29 ms | 764 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int solve(vector <int>&a){
vector <int> mq ,dq;
int ret = INT_MAX;
for(int i=0; i<a.size(); i++){
while(!mq.empty() && a[mq.back()] < a[i])
mq.pop_back();
while(!dq.empty() && a[dq.back()] > a[i])
dq.pop_back();
if(!mq.empty() && (dq.empty() || (a[dq.back()] >= a[i] || dq.back() <= mq.back())))
ret = min(ret ,a[mq.back()]-a[i]);
mq.push_back(i);
dq.push_back(i);
}
return ret;
}
int main()
{
int n;
scanf("%d",&n);
vector <int> a(n);
for(int&i : a)
scanf("%d",&i);
int p = solve(a);
reverse(a.begin() ,a.end());
cout << min(p ,solve(a)) << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |