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 <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define lli long long int
#define pll pair<lli,lli>
//para sol
#define pend first
#define ord second
lli n,d,a,b,offset;
pll sol;
multiset<lli> menores,mayores;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> d;
offset = 0;
rep(i,1,n) {
cin >> a;
if (!menores.empty()) b = (*menores.rbegin());
else b = 0;
b -= offset;
if (a > b) {
b = a - offset;
mayores.insert(b);
mayores.insert(b);
auto it = mayores.begin();
b = (*it);
mayores.erase(it);
b += offset*2;
menores.insert(b);
}
else {
b = a + offset;
menores.insert(b);
menores.insert(b);
auto it = menores.end();
it--;
b = (*it);
menores.erase(it);
b -= offset*2;
mayores.insert(b);
}
sol.pend++;
sol.ord -= a;
//ahora recorro
sol.ord -= sol.pend*d;
offset += d;
}
auto it = mayores.end();
do {
it--;
sol.pend--;
sol.ord += offset+(*it);
} while (it != mayores.begin());
cout << sol.ord;
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... |