24962023-01-13 20:15:53kohumarkTV szolgáltatókcpp11Wrong answer 12/4035ms5856 KiB
#include <iostream>
using namespace std;

int mi, ma, x, n, k;

long long es(int x, int bj[][2]) {
    int e=x+k-1;
    int c=0;
    for (int i=0; i<n; i++) {
        c+=max(0, bj[i][0]-x);
        c+=max(0, e-bj[i][1]);
    }
    return c;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	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]--;
	}
	
	
	mi=-1; ma=veg;
    while(ma-mi>1){
        x=(ma+mi)/2;
        if (es(x,bj)>es(x+1,bj)) mi=x;
        else ma=x;
    }
    
    cout << min(es(mi,bj), es(ma,bj));
}
SubtaskSumTestVerdictTimeMemory
base12/40
1Accepted0/03ms1892 KiB
2Accepted0/02ms2088 KiB
3Accepted1/12ms2292 KiB
4Accepted1/12ms2396 KiB
5Accepted1/12ms2604 KiB
6Accepted1/12ms2808 KiB
7Accepted2/22ms3008 KiB
8Accepted2/22ms3108 KiB
9Accepted2/22ms3212 KiB
10Accepted2/22ms3312 KiB
11Wrong answer0/214ms4056 KiB
12Wrong answer0/214ms4060 KiB
13Wrong answer0/214ms4056 KiB
14Wrong answer0/214ms4204 KiB
15Wrong answer0/228ms4828 KiB
16Wrong answer0/228ms4836 KiB
17Wrong answer0/218ms4188 KiB
18Wrong answer0/218ms4260 KiB
19Wrong answer0/218ms4392 KiB
20Wrong answer0/218ms4472 KiB
21Wrong answer0/118ms4464 KiB
22Wrong answer0/118ms4596 KiB
23Wrong answer0/135ms5596 KiB
24Wrong answer0/135ms5676 KiB
25Wrong answer0/135ms5656 KiB
26Wrong answer0/135ms5788 KiB
27Wrong answer0/135ms5852 KiB
28Wrong answer0/135ms5856 KiB