24972023-01-13 20:19:57kohumarkTV szolgáltatókcpp11Wrong answer 12/4035ms5724 KiB
#include <iostream>
using namespace std;

int n, k, l[100005], r[100005];
long long mi, ma, x;

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

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> k;
	int veg=0;
	for(int i=0; i<n; i++){
		cin >> l[i] >> r[i];
		veg=max(veg,r[i]);
	}
	
	
	mi=0; ma=veg+1;
    while(ma-mi>1){
        x=(ma+mi)/2;
        if (es(x)>es(x+1)) mi=x;
        else ma=x;
    }
    
    cout << min(es(mi), es(ma));
}
SubtaskSumTestVerdictTimeMemory
base12/40
1Accepted0/03ms2184 KiB
2Accepted0/02ms2220 KiB
3Accepted1/12ms2208 KiB
4Accepted1/12ms2420 KiB
5Accepted1/12ms2780 KiB
6Accepted1/12ms2836 KiB
7Accepted2/22ms2916 KiB
8Accepted2/22ms3248 KiB
9Accepted2/22ms3356 KiB
10Accepted2/22ms3240 KiB
11Wrong answer0/214ms4004 KiB
12Wrong answer0/214ms4208 KiB
13Wrong answer0/214ms4284 KiB
14Wrong answer0/214ms4336 KiB
15Wrong answer0/228ms5312 KiB
16Wrong answer0/228ms5384 KiB
17Wrong answer0/218ms4744 KiB
18Wrong answer0/218ms4752 KiB
19Wrong answer0/218ms4748 KiB
20Wrong answer0/218ms4752 KiB
21Wrong answer0/118ms4752 KiB
22Wrong answer0/118ms4748 KiB
23Wrong answer0/135ms5596 KiB
24Wrong answer0/135ms5516 KiB
25Wrong answer0/135ms5524 KiB
26Wrong answer0/135ms5520 KiB
27Wrong answer0/135ms5724 KiB
28Wrong answer0/135ms5724 KiB