#include <bits/stdc++.h>
using namespace std;
#include "grader.h"
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N=getN(),K=getK();
if(N>1000)exit(1);
vector<int>v;
auto calc=[&](int x)->int{
int c=0;
for(int i:v){
if(i<x){
c+=x-i;
}
if(i>x+K){
c+=i-(x+K);
}
}
return c;
};
for(int i=0;i<N;i++){
v.push_back(Data());
int l=-1e9,h=1e9;
while(h-l>=3){
int m1=l+(h-l)/3;
int m2=h-(h-l)/3;
if(calc(m1)<=calc(m2)){
h=m2;
}
else{
l=m1;
}
}
int ans=1e18;
for(int i=l;i<=h;i++){
ans=min(ans,calc(i));
}
Solution(ans);
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1832 KiB | ||||
2 | Accepted | 3ms | 2052 KiB | ||||
subtask2 | 0/20 | ||||||
3 | Accepted | 4ms | 2248 KiB | ||||
4 | Accepted | 8ms | 2464 KiB | ||||
5 | Accepted | 14ms | 2524 KiB | ||||
6 | Accepted | 23ms | 2736 KiB | ||||
7 | Accepted | 46ms | 2716 KiB | ||||
8 | Runtime error | 3ms | 2832 KiB | ||||
subtask3 | 20/20 | ||||||
9 | Accepted | 115ms | 3056 KiB | ||||
10 | Accepted | 115ms | 3144 KiB | ||||
11 | Accepted | 115ms | 3280 KiB | ||||
12 | Accepted | 115ms | 3348 KiB | ||||
13 | Accepted | 115ms | 3352 KiB | ||||
14 | Accepted | 115ms | 3352 KiB | ||||
subtask4 | 0/20 | ||||||
15 | Runtime error | 2ms | 3332 KiB | ||||
16 | Runtime error | 3ms | 3336 KiB | ||||
17 | Runtime error | 3ms | 3564 KiB | ||||
18 | Runtime error | 3ms | 3676 KiB | ||||
19 | Runtime error | 3ms | 3888 KiB | ||||
20 | Runtime error | 3ms | 3976 KiB | ||||
subtask5 | 0/40 | ||||||
21 | Runtime error | 3ms | 4100 KiB | ||||
22 | Runtime error | 3ms | 4180 KiB | ||||
23 | Runtime error | 3ms | 4188 KiB | ||||
24 | Runtime error | 3ms | 4312 KiB | ||||
25 | Runtime error | 3ms | 4396 KiB | ||||
26 | Runtime error | 3ms | 4400 KiB |