# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
586390 | hibiki | Safety (NOI18_safety) | C++11 | 58 ms | 4684 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;
long long n,h;
long long a;
long long y_min = 0, shift;
priority_queue<long long> l, r;
int main()
{
scanf("%lld %lld",&n,&h);
scanf("%lld",&a);
l.push(a);
r.push(-a);
for(int i = 1; i < n; i++)
{
scanf("%lld",&a);
shift += h;
long long curl = l.top() - shift;
long long curr = - r.top() + shift;
if(curl <= a && a <= curr)
{
l.push(a + shift);
r.push(-(a - shift));
}
else if(a < curl)
{
y_min += curl - a;
r.push(-(curl - shift));
l.pop();
l.push(a + shift);
l.push(a + shift);
}
else if(curr < a)
{
y_min += a - curr;
l.push(curr + shift);
r.pop();
r.push(-(a - shift));
r.push(-(a - shift));
}
}
printf("%lld\n",y_min);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |