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
#define pii pair<int,int>
const ll inf=1987654321987654321;
int a,b;
ll o[222222];
priority_queue<ll> l;
priority_queue<ll,vector<ll>,greater<ll>> r;
int main()
{
cin>>a>>b;
for(int t=1;t<=a;t++)
cin>>o[t];
ll ans=0;
l.push(o[1]);
r.push(o[1]);
for(int t=2;t<=a;t++)
{
ll x=l.top()-(ll)(t-1)*b,y=r.top()+(ll)(t-1)*b;
if(x<=o[t]&&o[t]<=y)
{
l.push(o[t]+(ll)(t-1)*b);
r.push(o[t]-(ll)(t-1)*b);
}
else if(o[t]<x)
{
ans+=x-o[t];
l.push(o[t]+(ll)(t-1)*b);
l.push(o[t]+(ll)(t-1)*b);
r.push(x-(ll)(t-1)*b);
l.pop();
}
else
{
ans+=o[t]-y;
r.push(o[t]-(ll)(t-1)*b);
r.push(o[t]-(ll)(t-1)*b);
l.push(y+(ll)(t-1)*b);
r.pop();
}
}
cout<<ans<<endl;
}
# | 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... |