#include <bits/stdc++.h>
using namespace std;
const int N = 2000;
int n, q[N], ql, qr, sum;
pair<int, int> list[N];
int maxSum;
int main() {
  scanf("%d", &n);
  int time = 0;
  for (int i = 0; i < n; i++) {
    int t, c;
    scanf("%d%d", &t, &c);
    while (ql < qr && time <= t) {
      int delta = min(t - time + 1, q[ql]);
      time += delta;
      q[ql] -= delta;
      sum -= delta;
      if (q[ql] == 0) ql++;
    }
    q[qr++] = c;
    sum += c;
    time = t + 1;
    maxSum = max(maxSum, sum);
  }
  while (ql < qr) {
    int delta = q[ql];
    time += delta;
    q[ql] -= delta;
    sum -= delta;
    if (q[ql] == 0) ql++;
  }
  printf("%d %d", time - 1, maxSum);
  return 0;
}
