hdu 6011 Lotus and Characters

Lotus has n 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 ≥0。 Input <dl><dd> First line is T(0T1000) T(0≤T≤1000) denoting the number of test cases.
For each test case,first line is an integer n(1n26) n(1≤n≤26),followed by n n lines each containing 2 integers vali,cnti(|vali|,cnti100) vali,cnti(|vali|,cnti≤100),denoting the value and the amount of the ith character.
</dd> Output <dd> For each test case.output one line containing a single integer,denoting the answer.
</dd> Sample Input <dd>
2
2
5 1
6 2
3
-5 3
2 1
1 1
</dd> Sample Output <dd>
35
5
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<iostream>
#include<set>

using namespace std;

#define  mem(x,y) memset(x,y,sizeof(x))
struct node
{
	int num, value;
	int f=0;
	friend bool operator<(const node &a, const node &b)
	{
		return a.value < b.value;
	}
};
node zi[10000];
int n;
int jia(int i)
{
	int t = 0;
	for (int j = 1; j <= i; j++)
	{
		t += j;
	}
	return t;
}
int main()
{
	
	int t;
	scanf("%d", &t);
	while (t--)
	{
		scanf("%d", &n);
		int sum=0;
		for (int i = 0; i < n; i++)
		{
			scanf("%d %d", &zi[i].value, &zi[i].num);
			if (zi[i].value > 0)
			{
				sum += zi[i].num*zi[i].value;
			}
		}

		sort(zi, zi + n);
		int a;
		int ans=0;
		int temp = 0;
		for (int i = n-1,k=1; i >= 0; i--)
		{
			int nowans = ans;
			for (int j = 0; j < zi[i].num; j++)
			{
				nowans = temp + nowans + zi[i].value;
				if (nowans > ans)
				{
					ans = nowans;
					a = zi[i].value;
					temp += a;
				}
				else if (nowans < ans)
				{
					break;
				}
			}
		}
		printf("%d\n", ans);
	
	}
	return 0;
}

//by swust_t_p </dd></dl>
全部评论

相关推荐

个人背景:学院二本计科专业&nbsp;大二开始实习个人经历:安克创新&nbsp;、理想汽车、字节跳动碎碎念:我做事只有三分钟热度。看到进了大厂的同学,我会羡慕,也会跟着努力上进;但遇到好看的小说,我又会放下手头的事沉迷其中,之前的坚持也就中断了。我有些自卑,总觉得自己学历和外貌都不够好。之前偶然在网上受到关注,我就喜欢上了上网,因为这里有很多人认可我。但我也很在意别人的评价,偶尔看到嘲讽的言论,会触发我的自卑情绪,让我感到愤怒。有时候我会强硬地回怼,有时候又会懦弱地选择无视。我也有虚荣心。不管是拿到安克、理想还是字节的机会,我在分享的时候都会带着这份心思。我会特意强调自己学历不好,是为了衬托出过程的艰难,以此显得自己更厉害。我知道,人往往会炫耀自己缺少的东西,来掩盖内心的空洞。我总想着走捷径,不太喜欢踏踏实实地做事。找实习的时候,我花了更多时间在研究面试技巧上,而不是提升专业能力。我会反复听面试录音分析技巧,看面试教程学习怎么和不同的面试官沟通,还会每天自言自语练习语言表达,同学都觉得我有点奇怪。我的实习生涯里,侥幸和运气占了很大一部分。我总在想,如果有一天我失去了这份幸运,这些特质可能会让我一蹶不振。ps:&nbsp;很多人会问我学习路线和经验&nbsp;但是就像我上面说的&nbsp;我的实习过程靠的很多是关键节点的运气&nbsp;技术上面我可能不如很多人&nbsp;&nbsp;所以请大家理性求助和理性参考我的回答&nbsp;附上我的投递记录
我的offer在哪里...:从去年看到现在,飞升哥就是榜样
我的求职进度条
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务