1738A. Glory Addicts(Codeforces Global Round 22)

A. Glory Addicts

time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

The hero is addicted to glory, and is fighting against a monster.

The hero has nn skills. The ii-th skill is of type aiai (either fire or frost) and has initial damage bibi.

The hero can perform all of the nn skills in any order (with each skill performed exactly once). When performing each skill, the hero can play a magic as follows:

  • If the current skill immediately follows another skill of a different type, then its damage is doubled.

In other words,

  1. If a skill of type fire and with initial damage cc is performed immediately after a skill of type fire, then it will deal cc damage;
  2. If a skill of type fire and with initial damage cc is performed immediately after a skill of type frost, then it will deal 2c2c damage;
  3. If a skill of type frost and with initial damage cc is performed immediately after a skill of type fire, then it will deal 2c2c damage;
  4. If a skill of type frost and with initial damage cc is performed immediately after a skill of type frost , then it will deal cc damage.

Your task is to find the maximum damage the hero can deal.

Input

Each test contains multiple test cases. The first line contains an integer tt (1≤t≤1051≤t≤105) — the number of test cases. The following lines contain the description of each test case.

The first line of each test case contains an integer nn (1≤n≤1051≤n≤105), indicating the number of skills.

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤10≤ai≤1), where aiai indicates the type of the ii-th skill. Specifically, the ii-th skill is of type fire if ai=0ai=0, and of type frost if ai=1ai=1.

The third line of each test case contains nn integers b1,b2,…,bnb1,b2,…,bn (1≤bi≤1091≤bi≤109), where bibi indicates the initial damage of the ii-th skill.

It is guaranteed that the sum of nn over all test cases does not exceed 105105.

Output

For each test case, output the maximum damage the hero can deal.

Example

input

Copy

 

4

4

0 1 1 1

1 10 100 1000

6

0 0 0 1 1 1

3 4 5 6 7 8

3

1 1 1

1000000000 1000000000 1000000000

1

1

1

output

Copy

2112
63
3000000000
1

Note

In the first test case, we can order the skills by [3,1,4,2][3,1,4,2], and the total damage is 100+2×1+2×1000+10=2112100+2×1+2×1000+10=2112.

In the second test case, we can order the skills by [1,4,2,5,3,6][1,4,2,5,3,6], and the total damage is 3+2×6+2×4+2×7+2×5+2×8=633+2×6+2×4+2×7+2×5+2×8=63.

In the third test case, we can order the skills by [1,2,3][1,2,3], and the total damage is 1000000000+1000000000+1000000000=30000000001000000000+1000000000+1000000000=3000000000.

In the fourth test case, there is only one skill with initial damage 11, so the total damage is 11.

挺有趣的一个题

题意就是有两种技能,如果两个技能间隔释放那么下一个技能伤害翻倍,比如第一次使用火焰技能下一次使用冻结技能伤害翻倍,但是如果下一次使用的是火焰技能伤害不变,求怎样放技能伤害最高。

我们可以对两个技能伤害分别进行排序,哪个技能最多就先释放技能最多的最小伤害,这样就能保证技能伤害高的技能吃到增幅从而打出成吨伤害。

这样操作完后剩下的技能就可以把伤害全部乘以2了。



#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int manx = 2e5 + 10;
int a[manx];
int b[manx];
bool cmp(int x, int y)
{
	return x>y;
}
void solve()
{
	vector<int>x, y;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < n; i++)
	{
		if (a[i])
		{
			x.push_back(b[i]);
		}
		else
		{
			y.push_back(b[i]);
		}
	}
	sort(x.begin(), x.end(),cmp);
	sort(y.begin(), y.end(),cmp);
	bool flag = false;
	long long sum = 0;
	while (x.size()>y.size())
	{
		sum += x.back(); x.pop_back();
		flag = true;
	}
	while (x.size()<y.size())
	{
		sum += y.back(); y.pop_back();
		flag = true;
	}
	if (!flag)//如果长度相等就先释放技能伤害最低的
	{
		if (x.back() <= y.back())
		{
			sum += x.back(); x.pop_back();
		}
		else
		{
			sum += y.back(); y.pop_back();
		}
	}
	while (x.size())
	{
		sum += 2 * x.back(); x.pop_back();
	}
	while (y.size())
	{
		sum += 2 * y.back(); y.pop_back();
	}
	cout << sum << endl;
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
马丁路德金的"I have a dream"节选存放在"freedom.txt"中: I have a dream that one day this nation will rise up, live up to the true meaning of its creed: “We hold these truths to be self-evident; that all men are created equal.” I have a dream that one day on the red hills of Georgia the sons of former slaves and the sons of former slave-owners will be able to sit down together at the table of br otherhood. I have a dream that one day even the state of Mississippi, a state sweltering with th e heat of injustice, sweltering with the heat of oppression, will be transformed into an oasis of freedom and justice. I have a dream that my four children will one day live in a nation where they will no t be judged by the color if their skin but by the content of their character. I have a dream today. I have a dream that one day down in Alabama with its governor having his lips drippin g with the words of interposition and nullification, one day right down in Alabama li ttle black boys and black girls will be able to join hands with little white boys and white girls as sisters and brothers. I have a dream today. I have a dream that one day every valley shall be exalted, every hill and mountain sh all be made low, the rough places will be made plain, and the crooked places will be made straight, and the glory of the Lord shall be revealed, and all flesh shall see i t together. 编程实现词汇表,计算每一个单词出现的次数,大小写不区分,输出到"dic.txt" 文件保存。
06-01

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值