Problem: Example

Input

2 5 4
5 7
4 8


Output

8 7

Solution (in CPP):

Solution:
#include <bits/stdc++.h>

using namespace std;

const int N = 155;
const long long INF = 2e18 + 5;

long long f[N][N];
int n, a, b, r[N], s[N];

int main() {
  cin >> n >> a >> b;
  for (int i = 1; i <= n; ++i) {
    cin >> r[i] >> s[i];
  }
  for (int i = n; i; --i) {
    s[i] += s[i + 1];
  }
  f[n + 1][0] = -INF;
  for (int i = n; i; --i) {
    for (int j = s[i]; j >= 0; --j) {
      f[i][j] = -INF;
      // eat
      if (s[i] - j + 1 <= s[i + 1]) {
        f[i][j] = 1 - r[i] - f[i + 1][s[i] - j + 1];
      }
      // pass
      if (j <= s[i + 1]) {
        f[i][j] = min(f[i][j], max(1LL, 1 + r[i] + f[i + 1][j]));
      }
    }
  }
  for (int i = s[1]; i >= 0; --i) {
    if (a - b >= f[1][i]) {
      cout << i << " " << s[1] - i << '\n';
      return 0;
    }
  }
  return 0;
}