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 <iostream>
#include <stdio.h>
#include <array>
#include <algorithm>
#include <cmath>
#include <queue>
/*
void showq(std::priority_queue<int> qL, std::priority_queue<int, std::vector<int>, std::greater<int>> qR)
{
while(!qL.empty())
{
std::cout << qL.top() << ' ';
qL.pop();
}
while(!qR.empty())
{
std::cout << ' ' << qR.top();
qR.pop();
}
std::cout << std::endl;
return;
}
*/
int main()
{
//freopen("duotaB.txt", "r", stdin);
int n;
long long h;
std::cin >> n >> h;
long long arr[n];
for(int i = 0; i < n; i++)
std::cin >> arr[i];
std::priority_queue<long long> qL;
std::priority_queue<long long, std::vector<long long>, std::greater<long long>> qR;
long long min = 0;
qL.emplace(arr[0]);
qR.emplace(arr[0]);
//showq(qL, qR);
for(long long i = 1; i < n; i++)
{
if(arr[i] + (long long)i*h < qL.top())
{
qL.emplace(arr[i] + (long long)i*h);
qL.emplace(arr[i] + (long long)i*h);
min += qL.top() - arr[i] - (long long)i*h;
qR.emplace(qL.top() - 2*(long long)i*h);
qL.pop();
}
else if(arr[i] - (long long)i*h > qR.top())
{
qR.emplace(arr[i] - (long long)i*h);
qR.emplace(arr[i] - (long long)i*h);
min += arr[i] - (long long)i*h - qR.top();
qL.emplace(qL.top() + (long long)2*(long long)i*h);
qR.pop();
}
else
{
qL.emplace(arr[i] + (long long)i*h);
qR.emplace(arr[i] - (long long)i*h);
}
//showq(qL, qR);
}
std::cout << min;
return 0;
}
# | 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... |