Descriptionios
Inputide
Outputui
Sample Inputthis
Sample Outputidea
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; int p[505],w[505],dp[10005]; int t,e,f,n; int main() { scanf("%d",&t); while(t--) { scanf("%d%d",&e,&f); f = f -e; scanf("%d",&n); for(int i = 0; i < n;i++) { scanf("%d%d",&p[i],&w[i]); } for(int i= 0;i<=f;i++) dp[i] = 9999999; dp[0]=0; for(int i=0;i < n;i++) for(int j = w[i];j <= f;j++) { dp[j] = min(dp[j -w[i]] + p[i],dp[j]); } if(dp[f]==9999999) puts("This is impossible."); else printf("The minimum amount of money in the piggy-bank is %d.\n",dp[f]); } return 0; }