#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
int n, k;
long long ans;
priority_queue<int> kis;
priority_queue<int, vector<int>, greater<int> > nagy;
int main()
{
n=getN(), k=getK();
for (int i=0; i<n; i++) {
int ert=Data();
kis.push(ert), nagy.push(ert+k);
int a=kis.top(), b=nagy.top();
if (a>b) {
ans+=a-b;
kis.pop(), nagy.pop();
kis.push(b), nagy.push(a);
}
Solution(ans);
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1892 KiB | ||||
2 | Accepted | 2ms | 2088 KiB | ||||
subtask2 | 20/20 | ||||||
3 | Accepted | 3ms | 2188 KiB | ||||
4 | Accepted | 4ms | 2400 KiB | ||||
5 | Accepted | 6ms | 2472 KiB | ||||
6 | Accepted | 7ms | 2604 KiB | ||||
7 | Accepted | 8ms | 2816 KiB | ||||
8 | Accepted | 1.126s | 4980 KiB | ||||
subtask3 | 20/20 | ||||||
9 | Accepted | 10ms | 2892 KiB | ||||
10 | Accepted | 14ms | 2896 KiB | ||||
11 | Accepted | 13ms | 3020 KiB | ||||
12 | Accepted | 10ms | 3100 KiB | ||||
13 | Accepted | 10ms | 3172 KiB | ||||
14 | Accepted | 13ms | 3096 KiB | ||||
subtask4 | 20/20 | ||||||
15 | Accepted | 68ms | 3420 KiB | ||||
16 | Accepted | 112ms | 3540 KiB | ||||
17 | Accepted | 93ms | 3540 KiB | ||||
18 | Accepted | 107ms | 3664 KiB | ||||
19 | Accepted | 114ms | 3776 KiB | ||||
20 | Accepted | 115ms | 3804 KiB | ||||
subtask5 | 40/40 | ||||||
21 | Accepted | 1.351s | 5692 KiB | ||||
22 | Accepted | 1.348s | 7120 KiB | ||||
23 | Accepted | 1.562s | 7040 KiB | ||||
24 | Accepted | 1.986s | 7164 KiB | ||||
25 | Accepted | 2.052s | 7608 KiB | ||||
26 | Accepted | 2.147s | 7488 KiB |