24882023-01-13 19:06:52kohumarkTV szolgáltatókcpp11Wrong answer 6/40981ms4624 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 petak=0; int minim=INT_MAX;
	
	int j=veg/2; int num=1; int pl=-1; int rossz=0;
	while((j>k-2&&j<veg)&&(rossz<2))
	for(int j=k-1; j<veg; j++){
		petak=0;
		for(int i=0; i<n; i++){
			if(j-k+1<bj[i][0]) petak+=bj[i][0]-(j-k+1);
			if(j>bj[i][1]) petak+=j-bj[i][1];
		}
		if(minim==min(minim,petak))rossz++;
		else rossz=0;
		minim=min(minim,petak);
		pl*=-1; num+=1; j=j+(pl*num);
	}
	
	cout << minim;
}
SubtaskSumTestVerdictTimeMemory
base6/40
1Accepted0/03ms1888 KiB
2Accepted0/02ms2216 KiB
3Accepted1/13ms2396 KiB
4Accepted1/12ms2520 KiB
5Accepted1/141ms2536 KiB
6Accepted1/165ms2608 KiB
7Accepted2/264ms2736 KiB
8Wrong answer0/2128ms2964 KiB
9Time limit exceeded0/2972ms2368 KiB
10Time limit exceeded0/2970ms2568 KiB
11Time limit exceeded0/2949ms3008 KiB
12Time limit exceeded0/2968ms3212 KiB
13Time limit exceeded0/2973ms3292 KiB
14Time limit exceeded0/2957ms3320 KiB
15Time limit exceeded0/2968ms3784 KiB
16Time limit exceeded0/2981ms3916 KiB
17Time limit exceeded0/2958ms3540 KiB
18Time limit exceeded0/2976ms3592 KiB
19Time limit exceeded0/2962ms3524 KiB
20Time limit exceeded0/2958ms3624 KiB
21Time limit exceeded0/1964ms3604 KiB
22Time limit exceeded0/1949ms3608 KiB
23Time limit exceeded0/1968ms4064 KiB
24Time limit exceeded0/1981ms4140 KiB
25Time limit exceeded0/1968ms4096 KiB
26Time limit exceeded0/1972ms4424 KiB
27Time limit exceeded0/1957ms4272 KiB
28Time limit exceeded0/1958ms4624 KiB