#include <bits/stdc++.h> using namespace std; int n,m,k,l,V,v,w; int f[1010],dp[1010]; void slove(){ cin>>n>>V; for(int i=1;i<=V;i++) dp[i]=-1e9; for(int i=1;i<=n;i++){ cin>>v>>w; for(int j=V;j>=v;j--){ f[j]=max(f[j],f[j-v]+w); dp[j]=max(dp[j],dp[j-v]+w); } } cout<<f[V]<<'\n'; if(dp[V]<0) cout<<0<<'\n'; else cout<<dp[V]<<'\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); int T=1; while (T--) { slove(); } return 0^0; }