codeforces-1271A - Suits

        A. Suits
 

A new delivery of clothing has arrived today to the clothing store. This delivery consists of aa ties, bb scarves, cc vests and dd jackets.

The store does not sell single clothing items — instead, it sells suits of two types:

  • a suit of the first type consists of one tie and one jacket;
  • a suit of the second type consists of one scarf, one vest and one jacket.

Each suit of the first type costs ee coins, and each suit of the second type costs ff coins.Calculate the maximum possible cost of a set of suits that can be composed

from the delivered clothing items. Note that one item cannot be used in more than one suit (though some items may be left unused).

Input

The first line contains one integer aa (1a100000) — the number of ties.

The second line contains one integer bb (1b100000) — the number of scarves.

The third line contains one integer cc (1c100000) — the number of vests.

The fourth line contains one integer dd (1d100000) — the number of jackets.

The fifth line contains one integer ee (1e1000)— the cost of one suit of the first type.

The sixth line contains one integer ff (1f1000) — the cost of one suit of the second type.

Output

Print one integer — the maximum total cost of some set of suits that can be composed from the delivered items.

Examples
Input
Copy
4
5
6
3
1
2
Output
Copy
6
Input
Copy
12
11
13
20
4
6
Output
Copy
102
Input
Copy
17
14
5
21
15
17
Output
Copy
325
Note

It is possible to compose three suits of the second type in the first example, and their total cost will be 66 . Since all jackets will be used, it's impossible to add anything to this set.

The best course of action in the second example is to compose nine suits of the first type and eleven suits of the second type. The total cost is 94+116=102.

题目大意:在一个服装店中有领带a个,围巾b个,背心c个,夹克d个。

现在有两种搭配:

1.a+d   e元

2.b+c+d f元

最佳搭配方案使得钱数最大

 

思路:比较e,f分类讨论

 

 

AC代码:

#pragma GCC optimize(2)
#include
using namespace std;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&(c<'0'||c>'9'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();return f*x;}
typedef long long ll;
const int maxn = 1e6+10;
int main()
{
    ll a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    if(e>=f){
        if(a>=d){
            printf("%lld\n",e*d);
        }
        else{
            ll sum=e*a;
            d-=a;
            ll t=min(b,min(c,d));
            sum+=f*t;
            printf("%lld",sum);
        }
    }
    else{
        ll t=min(b,min(c,d));//求三数最小值 
        ll sum=t*f;
        d-=t;
        if(d>0){
            int y=min(a,d);
            sum+=e*y;
        }
        printf("%lld",sum);
    } 
    return 0;
}

 

 

 

 

 

你可能感兴趣的:(codeforces-1271A - Suits)