Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.
Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!
Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.
The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).
Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.
5 1 3 4
800
1 1 1 1
256
这个题的题意就是说Anton有k2个数字2,k3个数字3,k5个数字5,k6个数字6,然后用这些数字组合成256和32,要求组合起来的数字和最大,数字可以有剩余。首先这个题当然是优先组成256了,然后看组合成256之后是否有足够的数字2和3能接着组成32就行了,代码如下:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int k1=2,k2=3,k3=5,k4=6;
int a,b,c,d;
int t=0,sum=0;
scanf("%d%d%d%d",&a,&b,&c,&d);
t=min(a,min(c,d));
if(t==a) sum=256*a;
if(t==c)
{
if(b>(a-c)) sum=256*c+(a-c)*32;
else if(b<=(a-c)) sum=256*c+b*32;
}
if(t==d)
{
if(b>(a-d)) sum=256*d+(a-d)*32;
else if(b<=(a-d)) sum=256*d+b*32;
}
printf("%d\n",sum);
return 0;
}