[ccOCT14] Magical Girl and Colored Liquid Potions

描述 Description

Naturally, the magical girl is very good at performing magic. She recently met her master wizard Devu, who gifted her R potions of red liquid,

B potions of blue liquid, and G potions of green liquid.

The red liquid potions have liquid amounts given by r[1], …, r[R] liters.

The green liquid potions have liquid amounts given by g[1], …, g[G] liters.

The blue liquid potions have liquid amounts given by b[1], …, b[B] liters.

She want to play with the potions by applying magic tricks on them. In a single magic trick, she will choose a particular color. Then she will pick all the potions of the chosen color and decrease the amount of liquid in them to half (i.e. if initial amount of liquid is x, then the amount after decrement will be x / 2 where division is integer division, e.g. 3 / 2 = 1 and 4 / 2 = 2).

Because she has to go out of station to meet her uncle Churu, a wannabe wizard, only M minutes are left for her. In a single minute, she can perform at most one magic trick. Hence, she can perform at most M magic tricks.

She would like to minimize the maximum amount of liquid among all of Red, Green and Blue colored potions. Formally Let v be the maximum value of amount of liquid in any potion. We want to minimize the value of v.

Please help her.

输入格式 InputFormat

First line of the input contains an integer T denoting the number of test cases.

Then for each test case, we have four lines.

The first line contains four space separated integers R, G, B, M. The next 3 lines will describe the amount of different color liquids (r, g, b), which are separated by space.

输出格式 OutputFormat

For each test case, print a single integer denoting the answer of the problem.

样例输入 SampleInput

3
1 1 1 1
1
2
3
1 1 1 1
2
4
6
3 2 2 2
1 2 3
2 4
6 8

样例输出 SampleOutput

2
4
4


CodeChef PRPOTION


代码 Code

因为同颜色药水所以只要考虑三种药水分别的最小值来计算即可。

#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int i,j,t,n,m,l,r,k,z,y,x;
int R,G,B,T,g,b;
int main()
{
    scanf("%d",&T);
    while (T--)
    {
        scanf("%d%d%d%d",&R,&G,&B,&m);
        r=g=b=0;
        for (i=1;i<=R;i++) scanf("%d",&t),r=max(r,t);
        for (i=1;i<=G;i++) scanf("%d",&t),g=max(g,t);
        for (i=1;i<=B;i++) scanf("%d",&t),b=max(b,t);
        while (m--)
        {
            if (r>=g && r>=b)
            {
                r/=2;
            }
            else if (g>=r && g>=b)
            {
                g/=2;
            }
            else 
            {
                b/=2;
            }
        }
        printf("%d\n",max(r,max(g,b)));
    }
    return 0;
}