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=200;
typedef long long ll;
ll f[N][N];
int n,a,b,r[N],s[N],c[N];
int main(){
	cin>>n>>a>>b;
	for(int i=1;i<=n;++i){
		cin>>r[i]>>s[i];
		c[i]=c[i-1]+s[i];
	}
	memset(f,63,sizeof f);
	for(int i=n;i;--i){
		int d=c[n]-c[i-1];
		for(int j=0;j<=d;++j)
			f[i][j]=min(-f[i+1][d-j+1]+1-r[i],max(r[i]+1+f[i+1][j],1ll));
	}
	for(int i=c[n];;--i)
		if(f[1][i]<=a-b){
			cout<<i<<" "<<c[n]-i<<endl;
			return 0;
		}
}