您的位置:首页 > 其它

URAL - 1788 On the Benefits of Umbrellas(水题)

2015-04-20 02:05 381 查看
On the Benefits of Umbrellas

Time Limit: 1000MSMemory Limit: 65536KB64bit IO Format: %I64d & %I64u
Submit Status

Description

A group of school leavers had their graduation party at an aquapark. They had a great time, but when they were leaving the aquapark they were surprised by a suddenly cold weather and a heavy rain, which made it quite a problem
to get to the trolleybus stop.

It turned out that all the boys in the company had their umbrellas and all the girls were without umbrellas. Of course, each boy, being a real gentleman, volunteered to accompany one of the girls to the trolleybus stop under
his umbrella.

If the ith girl gets wet under the rain, she'll get upset by gi units. If no girl accepts an invitation from the jth boy, he'll get upset
by bj · k units, where k is the number of luckier boys who will accompany girls under their umbrellas. The girls who will go under umbrellas
and the accompanying boys will not get upset at all.

Help the boys and girls keep their holiday mood as unspoiled as possible. Determine how they should proceed to make the total upset minimal.

Input

The first line contains the number of girls n and boys m in the group (1 ≤ n, m ≤ 100). The second
line contains the girls' upsets g1, …, gnseparated with a space. The third line contains the boys' upset coefficients b1, …, bm separated
with a space. The numbers in the second and third lines are positive integers not exceeding 1000.

Output

Output the minimal possible total upset.

Sample Input

inputoutput
2 4
1 100
10 8 6 4

19

1<=n,m<=100,于是直接枚举就好了。

#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int a, int b)
{
	return a > b;
}
int main()
{
	int n, m;
	int a[105], b[105];
	while (cin >> n >> m)
	{
		for (int i = 0; i < n; i++)
			cin >> a[i];
		for (int i = 0; i < m; i++)
			cin >> b[i];
		sort(a, a + n, cmp);
		sort(b, b + m, cmp);
		int ans = 10e6;
		int d = min(n, m);
		for (int i = 0; i <= d; i++)
		{
			int temp1 = 0, temp2 = 0, temp;
			for (int j = i; j < n; j++)
				temp1 += a[j];
			for (int j = i; j < m; j++)
				temp2 += b[j];
			temp = temp1 + temp2*i;
			ans = min(ans, temp);
		}
		cout << ans << endl;
	}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: