//============================================================================
// Name : mmmmmmmm.cpp
// Author : sameh mohamed
// Copyright : don't try i'm warnning you......
// Description : Hello World
//============================================================================
//Egypt came then History
//Pharoas were coders but using different compilers{}{}{}{}{}}}}{{{{@#$%^^&&$$$###()()(***)))([][][][][]]][
#include<bits/stdc++.h>
#include <iostream>
#include<string>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
long long ss(long long n)
{
long long c=0;
while(n)
{
long long m=log2(n);
n=n-exp2(m);
c++;
}
return c;
}
long long gcd(long long a,long long b)
{
if(a==0)
return b;
else if(b==0)
return a;
else
while(a!=b)
{
if(a>b)
a-=b;
else
b-=a;
}
return a;
}
long long minc=1e9;
int main()
{
int n,d;
cin>>n>>d;
long long a[n][2];
for(int i=0;i<n;i++)
{
cin>>a[i][0]>>a[i][1];
long long m=min(a[i][0],a[i][1]);
minc=min(minc,m);
}
long long s=0;
for(int i=0;i<n;i++)
{
long long h=min(a[i][0],a[i][1]);
long long m=min(a[i][0]+a[i][1],h+d+minc);
s+=m;
}
cout<<s;
return 0;
}
Copy