#include #include #include #include #include #include using namespace std; #define REP(i,n) for(int i=0;i<(n);++i) #define REPS(i,s,t) for(int i=(s);i<(t);++i) #define INF 2000000007 #define MOD 1000007 #define MAX 105 typedef unsigned int uint; typedef unsigned long long int ull; typedef long long int ll; int DP[MAX][100005]; int main(){ int N;cin>>N; vector V(N); vector W(N); REP(i,N){cin>>V[i]>>W[i];} int maxV;cin>>maxV; REPS(i,1,N+1){ REPS(j,1,100001){ if(j-W[i-1]<0){ DP[i][j]=DP[i-1][j]; continue; } DP[i][j] = max(DP[i-1][j],DP[i-1][j-W[i-1]]+V[i-1]); } } int k=0; while(DP[N][k++]!=maxV); cout << (k-1) << endl; while(DP[N][++k]==maxV); cout << (k-1) << endl; return 0; }