HDU 6011

来源:互联网 发布:照片马赛克软件 编辑:程序博客网 时间:2024/06/16 16:47

Lotus and Characters

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 0。

Input

First line is T(0T1000)
denoting the number of test cases.
For each test case,first line is an integer n(1n26),followed by n lines each containing 2 integers vali,cnti(|vali|,cnti100)
,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
225 16 23-5 32 11 1
Sample Output
355

          

解释一下测试数据:每次的价值数据都要先进行排序,选出价值大的放在前面

比如第一组测试数据 5 1    6 2;显然6的价值更高,因此把6放在后面,就是6*2+6*3;再是5,就是5*1,结果就为35,再是第二组数据:排好序后就变成2  1  -5;

应该就是2*2+1*1=5;如果是2*3+1*2+(-5)*1的话值是小于0的,因此-5数据直接舍弃了。

已经AC过的代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
pair<int,int> p[35];
int main()
{
    int t,n,v,c;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d %d",&v,&c);
            p[i]=make_pair(v,c);
        }
        long long sum=0;
        long long ans=0;
        sort(p,p+n);
        for(int i=n-1;i>=0;i--)
        {
            for(int j=0;j<p[i].second;j++)
            {
                ans+=p[i].first;
                if(ans<0)
                    break;
                sum+=ans;
            }
        }
        cout<<sum<<'\n';
    }
    return 0;
}
//用到了一些pair函数的使用,此前的博客里已经说明过了怎么使用。                                                       

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 新锐大灯光散不聚怎么办 网络碰到垃圾人怎么办 有人侮辱我家人怎么办 亲人欠网贷还不上现在病重怎么办 亲人欠网贷现在病重怎么办 小孩子大嘴巴病怎么办 小孩子有心胀病怎么办 小孩子有胃痛病怎么办 大修基金用完了怎么办 基金买错了怎么办 基金公司倒闭了怎么办 桔子分期有风险怎么办 想买vivox21没钱怎么办 中介收钱不办事怎么办 手机应用程序几个运行怎么办 网上彩票是骗局怎么办 辞职后不想辞职怎么办 口头辞职后悔了怎么办 纸质承兑丢了怎么办 天天利财倒闭怎么办 网络理财平台诈骗怎么办 银行理财产品到期后怎么办 30岁没工作怎么办 理财投资被骗了怎么办 支付宝不想收钱怎么办 信融财富逾期怎么办 拼多多砍价上限怎么办 肺功能只有50%怎么办 办小商店营业执照怎么办 悉尼退税未到账怎么办 筋斗云钱包余额怎么办 在监狱得了癌症怎么办 国外客户不付款怎么办 日上免税店超额怎么办 淘宝评价被删怎么办 个人集资不还怎么办 淘宝达人扣54分怎么办? 微信声音关不掉怎么办 微信头像换不掉怎么办 快件到了不签收怎么办 收货地址改不了怎么办