1 #include<stdio.h> 2 int d[10010]; 3 int main() 4 { 5 int i,j,n,pig,total,v,w,T; 6 scanf("%d",&T); 7 while(T--) 8 { 9 scanf("%d%d%d",&pig,&total,&n); 10 total-=pig; 11 memset(d,0x3f,sizeof(d)); 12 for(d[0]=0,i=0;i<n;++i){ 13 scanf("%d%d",&v,&w); 14 for(j=w;j<=total;++j) 15 d[j]<?=d[j-w]+v; 16 } 17 if(d[total]<0x3f3f3f3f) 18 printf("The minimum amount of money in the piggy-bank is %d.\n",d[total]); 19 else 20 puts("This is impossible."); 21 } 22 return 0; 23 }