#include <bits/stdc++.h>   using namespace std;   int dp[2][4004];   struct node {     int st;     int cost;   } save[4004];   int n, k;   void checkmin(int &a, int b) {     if (a == -1 || a > b) a = b;   }   int main() {     int i, j;     int ans;     while (~scanf( %d%d , &n, &k)) {       memset(dp, -1, sizeof(dp));       for (i = 1; i <= n; i++) {         scanf( %d%d , &save[i].st, &save[i].cost);         save[i].cost;       }       dp[0][0] = 1;       save[i].st = 86400 + 1;       ans = save[1].st - 1;       for (i = 1; i <= n; i++)         for (j = 0; j <= k && j <= i; j++) {           if (j == 0) {             if (dp[(i - 1) & 1][0] != -1) {               if (save[i].st > dp[(i - 1) & 1][0])                 dp[i & 1][0] = save[i].st + save[i].cost;               else                 dp[i & 1][0] = dp[(i - 1) & 1][0] + save[i].cost;             }             if (dp[i & 1][0] != -1) ans = max(ans, save[i + 1].st - dp[i & 1][0]);           } else {             if (dp[(i - 1) & 1][j - 1] != -1)               dp[i & 1][j] = dp[(i - 1) & 1][j - 1];             if (dp[(i - 1) & 1][j] != -1) {               if (save[i].st > dp[(i - 1) & 1][j])                 checkmin(dp[i & 1][j], save[i].st + save[i].cost);               else                 checkmin(dp[i & 1][j], dp[(i - 1) & 1][j] + save[i].cost);             }             if (dp[i & 1][j] != -1) ans = max(ans, save[i + 1].st - dp[i & 1][j]);           }         }       printf( %d n , ans);     }   }   