Code
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1010
#define W 1010
using namespace std;
int dp[W],v[N],w[N],n,m,p;
bool Check(int x)
{
memset(dp,0,sizeof(dp));
for (int i = 1;i <= n;++i)
{
if (w[i] > x) continue ;
for (int j = m;j >= w[i];--j)
dp[j] = max(dp[j],dp[j - w[i]] + v[i]);
}
if(dp[m] < p) return 0;
return 1;
}
void solve()
{
int lb = 0,ub = m;
while(lb + 1 < ub){
int mid = (lb + ub)/2;
//mid should be smaller
if(Check(mid)) ub = mid;
else lb = mid;
}
if(ub == m) printf("No Solution!");
else printf("%d",ub);
}
int main()
{
scanf("%d%d%d",&n,&p,&m);
for(int i = 1;i <= n;++i){
scanf("%d%d",&w[i],&v[i]);
}
solve();
return 0;
}