24982023-01-13 20:21:05kohumarkTV szolgáltatókcpp11Wrong answer 12/4037ms6264 KiB
#include <iostream>
using namespace std;

int n, k, l[100005], r[100005];
long long mi=0, ma=1e9+1, 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]);
	}
	
    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/03ms1780 KiB
2Accepted0/02ms2088 KiB
3Accepted1/12ms2148 KiB
4Accepted1/12ms2360 KiB
5Accepted1/12ms2696 KiB
6Accepted1/12ms2768 KiB
7Accepted2/22ms2844 KiB
8Accepted2/22ms3068 KiB
9Accepted2/22ms3248 KiB
10Accepted2/22ms3584 KiB
11Wrong answer0/217ms4296 KiB
12Wrong answer0/217ms4428 KiB
13Wrong answer0/217ms4604 KiB
14Wrong answer0/217ms4680 KiB
15Wrong answer0/232ms5648 KiB
16Wrong answer0/232ms5724 KiB
17Wrong answer0/219ms4968 KiB
18Wrong answer0/219ms5088 KiB
19Wrong answer0/219ms5092 KiB
20Wrong answer0/219ms5088 KiB
21Wrong answer0/119ms5164 KiB
22Wrong answer0/119ms5444 KiB
23Wrong answer0/137ms5984 KiB
24Wrong answer0/137ms5988 KiB
25Wrong answer0/137ms5984 KiB
26Wrong answer0/137ms5988 KiB
27Wrong answer0/137ms6192 KiB
28Wrong answer0/137ms6264 KiB