102412024-03-29 17:50:29111Egyengetőcpp17Time limit exceeded 20/1003.595s3360 KiB
#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)<=v.size()-c1-c2?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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1828 KiB
2Accepted3ms2036 KiB
subtask20/20
3Accepted4ms2248 KiB
4Accepted14ms2332 KiB
5Accepted34ms2468 KiB
6Accepted75ms2808 KiB
7Accepted229ms3028 KiB
8Time limit exceeded3.569s2432 KiB
subtask320/20
9Accepted1.075s2984 KiB
10Accepted987ms2984 KiB
11Accepted981ms3116 KiB
12Accepted967ms3236 KiB
13Accepted971ms3080 KiB
14Accepted1.072s3080 KiB
subtask40/20
15Time limit exceeded3.595s3072 KiB
16Time limit exceeded3.594s2272 KiB
17Time limit exceeded3.595s2516 KiB
18Time limit exceeded3.594s3344 KiB
19Time limit exceeded3.594s2720 KiB
20Time limit exceeded3.594s2664 KiB
subtask50/40
21Time limit exceeded3.558s2564 KiB
22Time limit exceeded3.563s2480 KiB
23Time limit exceeded3.555s3284 KiB
24Time limit exceeded3.553s3360 KiB
25Time limit exceeded3.536s2544 KiB
26Time limit exceeded3.53s2876 KiB