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 int long long
signed main()
{
#ifdef ONPC
freopen ("input.txt", "r", stdin);
#endif // ONPC
#ifndef ONPC
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif // ONPC
int n, dmax, sol = 0, lazy = 0;
cin >> n >> dmax;
multiset<int> a, b;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
if (i == 0)
{
a.insert(x);
b.insert(x);
continue;
}
lazy += dmax;
auto ita = a.end();
ita--;
if (x <= *ita - lazy)
{
sol += *ita - lazy - x;
b.insert(*ita - lazy - lazy);
a.erase(ita);
a.insert(x + lazy);
a.insert(x + lazy);
}
else
{
auto itb = b.begin();
if (x >= *itb + lazy)
{
sol += x - (*itb + lazy);
a.insert(*itb + lazy + lazy);
b.erase(itb);
b.insert(x - lazy);
b.insert(x - lazy);
}
else
{
a.insert(x + lazy);
b.insert(x - lazy);
}
}
}
cout << sol << "\n";
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... |