#include <iostream> #include <algorithm> using namespace std; int main() { int wr[4]; int rate[4]; int count=0; while(cin>>wr[0]) { cin>>rate[0]; cin>>wr[1]>>rate[1]; cin>>wr[2]>>rate[2]; cin>>rate[3]; wr[3]=1000; int w; cout<<"Set number "<<++count<<':'<<endl; while(cin>>w&&w!=0) { int i; for(i=0;i<4;i++) if(w<=wr[i]){ break; } int real_sum[4]; real_sum[i]=w*rate[i]; if(i==3) cout<<"Weight ("<<w<<") has best price $"<<real_sum[i]<<" (add 0 pounds)"<<endl; else { for(int j=i+1;j<4;j++) { real_sum[j]=(wr[j-1]+1)*rate[j]; } int* ptr=min_element(real_sum+i,real_sum+4); int script=ptr-real_sum; if(script!=i) cout<<"Weight ("<<w<<") has best price $"<<*ptr<<" (add "<<wr[script-1]+1-w<<" pounds)"<<endl; else cout<<"Weight ("<<w<<") has best price $"<<*ptr<<" (add 0 pounds)"<<endl; } } cout<<endl; } return 0; }