#include void chmin(int* a, int b) { if (*a > b) *a = b; } void chmax(int* a, int b) { if (*a < b) *a = b; } int main() { const int sup = 1 << 30; int i, N, D, P[1001], Q[1001], min[2] = {sup, sup}, argmin[2]; scanf("%d %d", &N, &D); for (i = 1; i <= N; i++) { scanf("%d %d", &(P[i]), &(Q[i])); if (min[0] > P[i]) { min[1] = min[0]; argmin[1] = argmin[0]; min[0] = P[i]; argmin[0] = i; } else if (min[1] > P[i]) { min[1] = P[i]; argmin[1] = i; } } int j, k, ans = -(1 << 30), tmp, tmpp; for (i = 1; i <= N; i++) { for (j = 1; j <= N; j++) { if (j == i) continue; tmp = Q[i] + Q[j] - P[i] - P[j]; if (tmp >= 0) { tmpp = -P[i]; chmin(&tmpp, -P[i] + Q[i] - P[j]); chmax(&ans, tmpp); } else if (D % 2 == 0) { tmpp = tmp * (D / 2) - Q[j]; if (argmin[0] != j) chmax(&tmpp, tmp * (D / 2 - 1) - P[i] + P[j] - min[0]); else chmax(&tmpp, tmp * (D / 2 - 1) - P[i] + P[j] - min[1]); chmin(&tmpp, tmp * (D / 2 - 1) - P[i]); chmax(&ans, tmpp); } else { tmpp = tmp * (D / 2) - P[i]; if (argmin[0] != i) chmax(&tmpp, tmp * (D / 2) - min[0]); else chmax(&tmpp, tmp * (D / 2) - min[1]); chmin(&tmpp, tmp * (D / 2) - Q[j]); chmax(&ans, tmpp); } } } printf("%d\n", ans); fflush(stdout); return 0; }