#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(),M=4e8;
if(N>1000)return 1;
vector<int>v;
auto calc=[&](int x)->int{
int c=0,c1=0,c2=0;
for(int i:v){
if(i<x){
c1++;
c+=x-i;
}
if(i>x+K){
c2++;
c+=i-(x+K);
}
}
return abs(c2-c1)<=v.size()-c1-c2?c:1e18;
};
for(int i=0;i<N;i++){
int y=Data();
v.push_back(y);
v.push_back(y-K);
sort(v.begin(),v.end());
int ans=1e18;
for(int j:v){
ans=min(ans,calc(j));
}
Solution(ans/2);
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Accepted | 3ms | 2052 KiB | ||||
subtask2 | 0/20 | ||||||
3 | Accepted | 6ms | 2236 KiB | ||||
4 | Accepted | 21ms | 2456 KiB | ||||
5 | Accepted | 61ms | 2804 KiB | ||||
6 | Accepted | 145ms | 3008 KiB | ||||
7 | Accepted | 451ms | 3108 KiB | ||||
8 | Runtime error | 3ms | 3204 KiB | ||||
subtask3 | 0/20 | ||||||
9 | Wrong answer | 3ms | 3296 KiB | ||||
10 | Wrong answer | 3ms | 3376 KiB | ||||
11 | Accepted | 2.003s | 3508 KiB | ||||
12 | Accepted | 1.975s | 3408 KiB | ||||
13 | Wrong answer | 3ms | 3380 KiB | ||||
14 | Wrong answer | 3ms | 3504 KiB | ||||
subtask4 | 0/20 | ||||||
15 | Runtime error | 3ms | 3712 KiB | ||||
16 | Runtime error | 3ms | 3948 KiB | ||||
17 | Runtime error | 3ms | 4144 KiB | ||||
18 | Runtime error | 3ms | 4240 KiB | ||||
19 | Runtime error | 3ms | 4364 KiB | ||||
20 | Runtime error | 2ms | 4364 KiB | ||||
subtask5 | 0/40 | ||||||
21 | Runtime error | 3ms | 4336 KiB | ||||
22 | Runtime error | 3ms | 4344 KiB | ||||
23 | Runtime error | 3ms | 4440 KiB | ||||
24 | Runtime error | 3ms | 4572 KiB | ||||
25 | Runtime error | 3ms | 4576 KiB | ||||
26 | Runtime error | 3ms | 4556 KiB |