您的位置:首页 > 其它

HDU-6011 Lotus and Characters

2017-10-18 14:17 501 查看
Lotus and Characters

 

 

Description

Lotus has $n$ kinds of characters,each kind of characters has a value and a amount.She wants to construct a string using some of these characters.Define the value of a string is:its first character's value*1+its second character's value *2+...She wants to
calculate the maximum value of string she can construct.

Since it's valid to construct an empty string,the answer is always $\geq 0$。

 

Input

First line is $T(0 \leq T \leq 1000)$ denoting the number of test cases.

For each test case,first line is an integer $n(1 \leq n \leq 26)$,followed by $n$ lines each containing 2 integers $val_i,cnt_i(|val_i|,cnt_i\leq 100)$,denoting the value and the amount of the ith character.

 

Output

For each test case.output one line containing a single integer,denoting the answer.

 

Sample Input

 2

2

5 1

6 2

3

-5 3

2 1

1 1

 

Sample Output

 35

5

#include<stdio.h>

#include<string.h>

#include<algorithm>

using namespace std;

int z[100008];

struct ha

{

    int a;

    int b;

}he[30];

int cmp(int a,int b)

{

    return a<b;

}

int main()

{

    int T;

    scanf("%d",&T);

    while(T--)

    {

        int n,i,j;

        scanf("%d",&n);

        int t=0,sum=0,ans=0;

        for(i=0;i<n;i++)

        {

            scanf("%d%d",&he[i].a,&he[i].b);

            while(he[i].b--)

            {

                z[t++]=he[i].a;

            }

        }

        sort(z,z+t,cmp);

        for(j=t-1;j>=0;j--)

        {

           // printf("%d\n",z[j]);

            sum+=z[j];

            if(sum<0)

                break;

            ans+=sum;

        }

        printf("%d\n",ans);

    }

    return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: