# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
553783 | hibiki | Safety (NOI18_safety) | C++11 | 57 ms | 5432 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 main()
{
int N;
long long H,s,shift=0,y_min=0;
priority_queue<long long> L,R;
scanf("%d %lld",&N,&H);
scanf("%lld",&s);
L.push(s);
R.push(-s);
for(int i=2;i<=N;i++)
{
shift+=H;
long long ll = L.top() - shift;
long long rr = -R.top() + shift;
scanf("%d",&s);
if(s<ll)
{
y_min += ll - s;
L.push(s + shift);
L.push(s + shift);
L.pop();
R.push(-(ll - shift));
}
else if(s>rr)
{
y_min += s - rr;
R.push(-(s - shift));
R.push(-(s - shift));
R.pop();
L.push(rr + shift);
}
else
{
L.push(s + shift);
R.push(-(s - shift));
}
}
printf("%lld\n",y_min);
return 0;
}
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... |