#include #include #include #include #include #include #include #include #include #include using namespace std; #define int long long int MOD = 1000000007; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N, M; cin >> N >> M; vector A(N); vector B(N); int res = 0; for (int i = 0; i < N; i++) { cin >> B[i] >> A[i]; } vector X(N + 1, 0); for (int i = N - 1; i >= 0; i--) { int t = max(A[i], B[i]); X[i] = max((int)0, X[i + 1] + t); } int a = 0; for (int i = 0; i < N; i++) { a += max(A[i], max(A[i] + (M - 1)* B[i], M*B[i])); //cerr << a + X[i + 1] << endl; res = max(res, a + X[i + 1]); } cout << res << endl; }