#include #include using namespace std; typedef long long ll; int main(){ ll n, m; cin>>n>>m; ll a[100001], b[100001]; ll sa[100001], sa2[100001], sd[100001], mx[100001], sd2[100001]; sa[0]=sd[0]=sd2[0]=sa2[0]=0; mx[0]=-1e18; if(m==1) mx[0]=0; for(int i=1; i<=n; i++){ cin>>a[i]>>b[i]; if(a[i]>=0){ sa[i]=sa[i-1]+a[i]; sa2[i]=sa2[i-1]+a[i]; sd[i]=sd[i-1]+max(0ll, b[i]-a[i]); sd2[i]=sd2[i-1]; }else{ sa[i]=sa[i-1]+b[i]; sa2[i]=sa2[i-1]; sd[i]=sd[i-1]; sd2[i]=sd2[i-1]+max(0ll, a[i]-b[i]); } mx[i]=max(mx[i-1], (m-1)*sa2[i]-sd2[i]); } ll ans=-1e18; for(int i=1; i<=n; i++){ ans=max(ans, sa[i]+sd[i]+mx[i]+sd2[i]); } cout<