21. 帆布画

Description

After last year's success, Samuel W. E. R. Craft's reputation has grown and he has now funded various projects. His latest idea involves creating an array of canvases with colored patterns without repeating colors.

Samuel bought a set of white canvasses of varying sizes. Since painting them manually would take too much time, he devised a huge machine to automate the painting process. The painting process works as follows:

  1. Assemble all canvasses in a line in the machine’s conveyor belt, disposed in some chosen order.

  1. Pick a color C and a number F (which should be less than the number of color C canvasses).

  1. Going from left to right, all canvasses with color C are painted. The first F color C canvasses are painted with a new color X and the remaining color C canvasses are painted with a new color Y . Colors X and Y are selected by the machine, are distinct, and are different from any color used previously. The amount of ink spent in this step is equal to the sum of the sizes of the painted canvasses.

  2. Repeat 2) and 3) until all canvasses have distinct colors.

Consider for example that Samuel bought four canvasses of sizes 3, 5, 5 and 7. The following picture shows 2 different options for painting them.

Given the sizes of the canvasses Samuel bought, can you help Samuel finding the minimum amount of ink the machine needs to spend in order to have all canvasses with different colors?

Input

The first line consists of a single integer T, the number of test cases. Each test case is composed by two lines. The first line consists of a single integer N representing the number of canvasses. The next line contains N space separated integers representing the sizes of the canvasses.

Output

The output contains T lines, one for each test case: the minimum amount of ink the machine needs in order to have all canvasses with different colors.

Note

# include<stdio.h>
# include<stdlib.h>
long long h[100010];
long long n, ans;
void swap(long long  x, long long y){
    long long t;
    t = h[x];
    h[x] = h[y];
    h[y] = t;
}
void siftdown(int i){
    long long t, flag = 0;
    while(i*2 <= n && flag == 0){
        if(h[i] > h[i*2])
            t = i * 2;
        else
            t = i;
        if(i*2+1 <= n){
            if(h[t] > h[i*2+1])
                t = i * 2 + 1;
        }
        if(t!=i){
            swap(t, i);
            i = t;
        }
        else
            flag = 1;
    }
}
void create(){
    long long i;
    for (i = n / 2; i >= 1;i--){
        siftdown(i);
    }
}

int main(){
    int T;
    scanf("%d", &T);
    while(T--){
        ans = 0;
        long long i, num;
        scanf("%lld", &num);
        for (i = 1; i <= num; i++)
            scanf("%lld", &h[i]);
        if(num == 1){
            printf("0\n");
            continue;
        }
        n = num;
        create();
        while(n > 2){
            if(h[2] < h[3]){
                ans = ans + h[1] + h[2];
                h[2] = h[1] + h[2];
                swap(1, n);
                n--;
                siftdown(2);
                siftdown(1);
            }
            else{
                ans = ans + h[1] + h[3];
                h[3] = h[1] + h[3];
                swap(1, n);
                n--;
                siftdown(3);
                siftdown(1);
            }
        }
        ans += h[1] + h[2];
        printf("%lld\n", ans);
    }
    return 0;
}

 

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
养虾的池塘材料一般有水泥、塑料、土壤等,其中比较常见的是帆布池。以下是帆布池养虾的教程及注意事项: 1. 池塘选址:选择一块平地,避免池塘建在低洼处或水流较快的地方。 2. 池塘准备:根据需要的池塘大小,选择合适尺寸的帆布池,清理池塘周围的杂草、石头、树枝等,确保池塘周围干净整洁。 3. 帆布池铺设:将帆布池铺放在平整的地面上,注意帆布池四周的边缘要铺平,以免发生漏水现象。 4. 池塘充水:在池塘内加入适量的水,水深不宜过浅或过深,一般建议水深在1.5米左右。 5. 添加养殖饵料:根据虾的品种和养殖的目的,选择适合的饵料,比如鱼粉、豆粉、米糠等。在虾苗投放前,需在水中添加充足的饵料,以促进虾苗的生长。 6. 投放虾苗:在虾池内投放虾苗,投放数量根据池塘的大小而定。虾苗投放前需进行适当的处理,比如消毒、浸泡等,以消除害虫和疾病的影响。 7. 日常养护:定期清理池塘一周围的杂草和底泥,避免过度积累。同时,要注意池塘水质的保持,定期检测水质,确保养殖环境健康。 注意事项: 1. 帆布池养虾的水源要保持清洁,避免水中杂质和有害物质的污染。 2. 养殖过程中,要注意虾苗的生长情况,及时调整养殖饵料的种类和用量。 3. 避免池塘过度养殖,以免引起疾病和污染。 4. 在池塘投放虾苗前,一定要进行虾苗的检疫和消毒,预防疾病的发生。 5. 养殖过程中,要注意池塘的通风和保湿,避免池塘水温过高或过低,影响虾的生长。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值