24952023-01-13 20:12:41kohumarkTV szolgáltatókcpp11Wrong answer 12/4035ms6264 KiB
#include <iostream>
#include <climits>
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=0; ma=veg-1;
    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/03ms1888 KiB
2Accepted0/02ms2124 KiB
3Accepted1/12ms2440 KiB
4Accepted1/12ms2500 KiB
5Accepted1/12ms2452 KiB
6Accepted1/12ms2668 KiB
7Accepted2/22ms2748 KiB
8Accepted2/23ms2852 KiB
9Accepted2/23ms3200 KiB
10Accepted2/23ms3336 KiB
11Wrong answer0/214ms4172 KiB
12Wrong answer0/214ms4376 KiB
13Wrong answer0/214ms4448 KiB
14Wrong answer0/214ms4580 KiB
15Wrong answer0/228ms5324 KiB
16Wrong answer0/228ms5476 KiB
17Wrong answer0/218ms4620 KiB
18Wrong answer0/218ms4624 KiB
19Wrong answer0/218ms4624 KiB
20Wrong answer0/218ms4752 KiB
21Wrong answer0/118ms4956 KiB
22Wrong answer0/118ms5088 KiB
23Wrong answer0/135ms5864 KiB
24Wrong answer0/135ms5988 KiB
25Wrong answer0/135ms6080 KiB
26Wrong answer0/135ms6168 KiB
27Wrong answer0/135ms6172 KiB
28Wrong answer0/135ms6264 KiB