24942023-01-13 20:07:04kohumarkTV szolgáltatókcpp11Wrong answer 12/4035ms5944 KiB
#include <iostream>
#include <climits>
using namespace std;

int mi, ma, x, n, k;

int 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=0; 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/02ms2084 KiB
3Accepted1/12ms2292 KiB
4Accepted1/12ms2364 KiB
5Accepted1/12ms2500 KiB
6Accepted1/12ms2700 KiB
7Accepted2/22ms2908 KiB
8Accepted2/22ms3124 KiB
9Accepted2/22ms3184 KiB
10Accepted2/22ms3336 KiB
11Wrong answer0/214ms4208 KiB
12Wrong answer0/214ms4380 KiB
13Wrong answer0/214ms4592 KiB
14Wrong answer0/214ms4708 KiB
15Wrong answer0/228ms5552 KiB
16Wrong answer0/228ms5552 KiB
17Wrong answer0/218ms4784 KiB
18Wrong answer0/218ms4996 KiB
19Wrong answer0/218ms5204 KiB
20Wrong answer0/218ms5088 KiB
21Wrong answer0/118ms5172 KiB
22Wrong answer0/118ms5084 KiB
23Wrong answer0/135ms5864 KiB
24Wrong answer0/135ms5944 KiB
25Wrong answer0/135ms5940 KiB
26Wrong answer0/135ms5944 KiB
27Wrong answer0/135ms5860 KiB
28Wrong answer0/135ms5860 KiB