#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;
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)<=1?c:1e18;
};
for(int i=0;i<N;i++){
v.push_back(Data());
sort(v.begin(),v.end());
int ans=1e18;
for(int j=0;j<=i;j++){
ans=min(ans,calc(v[j]));
ans=min(ans,calc(v[j]-K));
}
Solution(ans);
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1824 KiB | ||||
2 | Accepted | 3ms | 2024 KiB | ||||
subtask2 | 0/20 | ||||||
3 | Accepted | 4ms | 2240 KiB | ||||
4 | Accepted | 16ms | 2344 KiB | ||||
5 | Accepted | 43ms | 2420 KiB | ||||
6 | Wrong answer | 8ms | 2552 KiB | ||||
7 | Wrong answer | 4ms | 2632 KiB | ||||
8 | Time limit exceeded | 3.571s | 2152 KiB | ||||
subtask3 | 0/20 | ||||||
9 | Accepted | 1.343s | 2856 KiB | ||||
10 | Accepted | 1.348s | 2984 KiB | ||||
11 | Accepted | 1.338s | 3068 KiB | ||||
12 | Accepted | 1.314s | 3196 KiB | ||||
13 | Accepted | 1.315s | 3280 KiB | ||||
14 | Wrong answer | 115ms | 3440 KiB | ||||
subtask4 | 0/20 | ||||||
15 | Wrong answer | 3ms | 3476 KiB | ||||
16 | Time limit exceeded | 3.595s | 2844 KiB | ||||
17 | Time limit exceeded | 3.592s | 2976 KiB | ||||
18 | Time limit exceeded | 3.594s | 3572 KiB | ||||
19 | Time limit exceeded | 3.592s | 2856 KiB | ||||
20 | Time limit exceeded | 3.595s | 2828 KiB | ||||
subtask5 | 0/40 | ||||||
21 | Time limit exceeded | 3.558s | 3476 KiB | ||||
22 | Wrong answer | 100ms | 3484 KiB | ||||
23 | Wrong answer | 4ms | 3480 KiB | ||||
24 | Time limit exceeded | 3.552s | 3480 KiB | ||||
25 | Time limit exceeded | 3.532s | 2940 KiB | ||||
26 | Time limit exceeded | 3.535s | 3500 KiB |