Blinds(百叶窗)

55 篇文章 0 订阅
22 篇文章 0 订阅

Description
The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are n blind stripes with the width of 1 in the factory warehouse for blind production. The problem is that all of them are spare details from different orders, that is, they may not have the same length (it is even possible for them to have different lengths)

Every stripe can be cut into two or more parts. The cuttings are made perpendicularly to the side along which the length is measured. Thus the cuttings do not change the width of a stripe but each of the resulting pieces has a lesser length (the sum of which is equal to the length of the initial stripe)

After all the cuttings the blinds are constructed through consecutive joining of several parts, similar in length, along sides, along which length is measured. Also, apart from the resulting pieces an initial stripe can be used as a blind if it hasn’t been cut. It is forbidden to construct blinds in any other way.

Thus, if the blinds consist of k pieces each d in length, then they are of form of a rectangle of k × d bourlemeters.

Your task is to find for what window possessing the largest possible area the blinds can be made from the given stripes if on technical grounds it is forbidden to use pieces shorter than l bourlemeter. The window is of form of a rectangle with side lengths as positive integers.

Input
The first output line contains two space-separated integers n and l (1 ≤ n, l ≤ 100). They are the number of stripes in the warehouse and the minimal acceptable length of a blind stripe in bourlemeters. The second line contains space-separated n integers ai. They are the lengths of initial stripes in bourlemeters (1 ≤ ai ≤ 100).

Output
Print the single number — the maximal area of the window in square bourlemeters that can be completely covered. If no window with a positive area that can be covered completely without breaking any of the given rules exist, then print the single number 0.

Sample Input
Input
4 2
1 2 3 4
Output
8
Input
5 3
5 5 7 3 1
Output
15
Input
2 3
1 2
Output
0
Hint
In the first sample test the required window is 2 × 4 in size and the blinds for it consist of 4 parts, each 2 bourlemeters long. One of the parts is the initial stripe with the length of 2, the other one is a part of a cut stripe with the length of 3 and the two remaining stripes are parts of a stripe with the length of 4 cut in halves.
题意:就是给你n个横条,l是最小的,然后从l —— 横条中最大的,使次数*横条的值最大。
代码如下:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
    int n, l, a[101], tp[200];
    while(~scanf("%d %d", &n, &l))
    {
        int ant = 0, maxx = 0;
        for(int i = 0;  i < n; i++)
            scanf("%d", &a[i]);
        sort(a, a + n);
        if(a[n - 1] < l) puts("0");
        else
        {
            for(int i = l; i <= a[n - 1]; i++)
            {
                ant = 0;
                for(int j = 0; j < n; j++)
                {
                    ant += (a[j] / i);
                }
                maxx = max(maxx, ant * i);
            }
            printf("%d\n", maxx);
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值