24912023-01-13 19:22:39kohumarkTV szolgáltatókcpp11Wrong answer 9/4037ms6168 KiB
#include <iostream>
#include <climits>
using namespace std;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, k; cin >> n >> k;
	int bj[n][2];
	int veg=0;
	for(int i=0; i<n; i++){
		cin >> bj[i][0] >> bj[i][1];
		veg=max(veg,bj[i][1]);
		bj[i][0]--; bj[i][1]--;
	}
	int petakmi=0; int petakma=0;
	
	
	int mi=k-1; int ma=veg;
	while(ma-mi>1){
		petakmi=0; petakma=0;
		for(int i=0; i<n; i++){
			if(mi-k+1<bj[i][0]) petakmi+=bj[i][0]-(mi-k+1);
			if(mi>bj[i][1]) petakmi+=mi-bj[i][1];
			if(ma-k+1<bj[i][0]) petakma+=bj[i][0]-(ma-k+1);
			if(ma>bj[i][1]) petakma+=ma-bj[i][1];
		}
		if(petakmi<petakma) ma=(mi+ma)/2;
		else mi=(mi+ma)/2;
	}
	
	cout << min(petakmi,petakma);
}
SubtaskSumTestVerdictTimeMemory
base9/40
1Accepted0/03ms1896 KiB
2Accepted0/02ms2084 KiB
3Accepted1/12ms2312 KiB
4Accepted1/12ms2360 KiB
5Wrong answer0/12ms2740 KiB
6Accepted1/12ms2820 KiB
7Accepted2/22ms3024 KiB
8Wrong answer0/22ms3012 KiB
9Accepted2/22ms3080 KiB
10Accepted2/22ms3208 KiB
11Wrong answer0/214ms4176 KiB
12Wrong answer0/216ms4508 KiB
13Wrong answer0/216ms4372 KiB
14Wrong answer0/216ms4372 KiB
15Wrong answer0/228ms5268 KiB
16Wrong answer0/228ms5364 KiB
17Wrong answer0/218ms4800 KiB
18Wrong answer0/218ms4780 KiB
19Wrong answer0/218ms4776 KiB
20Wrong answer0/218ms5052 KiB
21Wrong answer0/118ms5164 KiB
22Wrong answer0/118ms5124 KiB
23Wrong answer0/137ms5960 KiB
24Wrong answer0/135ms5956 KiB
25Wrong answer0/137ms5964 KiB
26Wrong answer0/137ms6112 KiB
27Wrong answer0/135ms6168 KiB
28Wrong answer0/135ms6032 KiB