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;
#define ll long long
ll n, h, lzl, lzr, s, ans;
priority_queue<ll> l;
priority_queue<ll, vector<ll>, greater<ll>> r;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>h;
for (int i=1; i<=n; i++)
{
cin>>s;
if (i>1&&s<l.top()+lzl)
{
l.push(s-lzl);
l.push(s-lzl);
ll tmp=l.top()+lzl;
ans+=tmp-s;
l.pop();
r.push(tmp-lzr);
}
else if (i>1&&s>r.top()+lzr)
{
r.push(s-lzr);
r.push(s-lzr);
ll tmp=r.top()+lzr;
ans+=s-tmp;
r.pop();
l.push(tmp-lzl);
}
else
{
l.push(s-lzl);
r.push(s-lzr);
}
lzl-=h; lzr+=h;
}
cout<<ans;
}
# | 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... |