Pick Apples The third ACM provincial race

Source: Internet
Author: User

Description

Once ago, there is a mystery yard which only produces three kinds of apples. The number of each kind is infinite. A girl carrying a big bag comes into the yard. She was so surprised because she had never seen so many apples before. Each kind of apple have a size and a price to be sold. Now the little girl wants to gain more profits, but she does isn't know how. So she asks to help, and tell she the most profits she can gain.

Input

The first line there are an integer t (t <=), indicates the number of test cases.
In each case, there is four lines. In the first three lines, there is both integers S and P in each line, which indicates the size (1 <= S <=) and The price (1 <= P <= 10000) of this kind of apple.

The fourth line there are an integer V, (1 <= V <= 100,000,000) indicates the volume of the girl ' s bag.

Output

For each case, first output of the case number then follow the most profits she can gain.

Sample Input

11 12 13 16

Sample Output

Case 1:6

#include <iostream>#include<stdio.h>#include<algorithm>using namespacestd;structn{ints,p; Doublepri;} node[4];BOOLCMP (N a,n b) {if(A.PRI&LT;B.PRI)return true; return false;}Long LongLlmax (Long LongALong Longb) {    returnA>b?a:b;}intMain () {intT; CIN>>T; intC=1;  while(t--)    {         for(intI=0;i<3; i++) {cin>>node[i].s>>NODE[I].P; Node[i].pri=1.0*node[i].s/(1.0*NODE[I].P); }        intV; CIN>>W; Sort (Node,node+3, CMP); Long Longans=0;  for(intI=0; i<node[0].S; i++)        {             for(intj=0; j<node[0].S; J + +)            {                Long Longtemp=i*node[1].s+j*node[2].s; if(temp>V) Break; Else                {                    Long Longv=v-temp; Ans=llmax (ans,v/node[0].s*node[0].p+i*node[1].p+j*node[2].P); } }} cout<<" Case"<<c++<<": "<<ans<<Endl; }    return 0;}

Pick Apples The third ACM provincial race

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.