#include #include using namespace std; #define int long long signed main(){ int N, M, hoge[2][2] = {}, x, ans = 0, a, b, num; scanf("%lld %lld", &N, &M); scanf("%lld %lld", &a, &b); x = max(b,a*(M-1)+max(a,b)); for(int i = 1; i < N; i++){ scanf("%lld %lld", &a, &b); num = max(a,b); hoge[(i+1)%2][1] = max(b,a*(M-1)+num)+hoge[i%2][1]; hoge[(i+1)%2][0] = max(hoge[i%2][0],hoge[i%2][1]) +num; ans = max(ans,max(hoge[(i+1)%2][0],hoge[(i+1)%2][1])); } ans += x; printf("%lld\n",ans); return 0; }