标签:
| Time Limit: 1000MS | Memory Limit: 65536KB | 64bit IO Format: %I64d & %I64u | 
Description
Input
Output
Sample Input
| input | output | 
|---|---|
| 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;
	}
}URAL - 1788 On the Benefits of Umbrellas(水题)
标签:
原文地址:http://blog.csdn.net/qq_18738333/article/details/45140365