102122024-03-29 15:21:31111Egyengetőcpp17Runtime error 20/100115ms4400 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();
	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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Accepted3ms2052 KiB
subtask20/20
3Accepted4ms2248 KiB
4Accepted8ms2464 KiB
5Accepted14ms2524 KiB
6Accepted23ms2736 KiB
7Accepted46ms2716 KiB
8Runtime error3ms2832 KiB
subtask320/20
9Accepted115ms3056 KiB
10Accepted115ms3144 KiB
11Accepted115ms3280 KiB
12Accepted115ms3348 KiB
13Accepted115ms3352 KiB
14Accepted115ms3352 KiB
subtask40/20
15Runtime error2ms3332 KiB
16Runtime error3ms3336 KiB
17Runtime error3ms3564 KiB
18Runtime error3ms3676 KiB
19Runtime error3ms3888 KiB
20Runtime error3ms3976 KiB
subtask50/40
21Runtime error3ms4100 KiB
22Runtime error3ms4180 KiB
23Runtime error3ms4188 KiB
24Runtime error3ms4312 KiB
25Runtime error3ms4396 KiB
26Runtime error3ms4400 KiB