#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;
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());
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 | 1828 KiB | ||||
2 | Accepted | 3ms | 2024 KiB | ||||
subtask2 | 0/20 | ||||||
3 | Accepted | 4ms | 2228 KiB | ||||
4 | Accepted | 14ms | 2452 KiB | ||||
5 | Accepted | 41ms | 2536 KiB | ||||
6 | Accepted | 90ms | 2660 KiB | ||||
7 | Accepted | 293ms | 2760 KiB | ||||
8 | Time limit exceeded | 3.569s | 2748 KiB | ||||
subtask3 | 20/20 | ||||||
9 | Accepted | 1.296s | 2884 KiB | ||||
10 | Accepted | 1.312s | 3224 KiB | ||||
11 | Accepted | 1.314s | 3456 KiB | ||||
12 | Accepted | 1.297s | 3560 KiB | ||||
13 | Accepted | 1.297s | 3732 KiB | ||||
14 | Accepted | 1.302s | 3812 KiB | ||||
subtask4 | 0/20 | ||||||
15 | Time limit exceeded | 3.595s | 3324 KiB | ||||
16 | Time limit exceeded | 3.594s | 3516 KiB | ||||
17 | Time limit exceeded | 3.595s | 4480 KiB | ||||
18 | Time limit exceeded | 3.594s | 3656 KiB | ||||
19 | Time limit exceeded | 3.595s | 4012 KiB | ||||
20 | Time limit exceeded | 3.595s | 3828 KiB | ||||
subtask5 | 0/40 | ||||||
21 | Time limit exceeded | 3.559s | 4060 KiB | ||||
22 | Time limit exceeded | 3.563s | 4052 KiB | ||||
23 | Time limit exceeded | 3.556s | 4072 KiB | ||||
24 | Time limit exceeded | 3.553s | 4016 KiB | ||||
25 | Time limit exceeded | 3.535s | 4744 KiB | ||||
26 | Time limit exceeded | 3.536s | 4652 KiB |