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

On the Benefits of Umbrellas

Time Limit: 1000MS   Memory Limit: 65536KB   64bit 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 ≤ nm ≤ 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

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;
	}
}
时间: 2024-10-13 11:21:58

URAL - 1788 On the Benefits of Umbrellas(水题)的相关文章

URAL 1023 Buttons(巴什博弈水题)

1023. Buttons Time limit: 2.0 secondMemory limit: 64 MB Background As you surely already know, Yekaterinburg has gotten its right to hold The Summer Olympic Games of the 2032. It is planned that it will be allowed to Russia as a country-organizer to

URAL 1039 Anniversary Party 树形DP 水题

1039. Anniversary Party Time limit: 0.5 secondMemory limit: 8 MB Background The president of the Ural State University is going to make an 80'th Anniversary party. The university has a hierarchical structure of employees; that is, the supervisor rela

2015南阳CCPC L - Huatuo&#39;s Medicine 水题

L - Huatuo's Medicine Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Huatuo was a famous doctor. He use identical bottles to carry the medicine. There are different types of medicine. Huatuo put medicines into the bottles and chain these b

sdut 2841 Bit Problem (水题)

题目 贴这个题是因为看题解有更简单的方法, 我做的时候是直接算的, 也很简单. 贴一下题解吧: 如果一个整数不等于 0,那么该整数的二进制表示中至少有一位是 1. 这个题结果可以直接输出 x - (x&(x-1)); 因为x-1 之后二进制下,就是最右边的1变成了0, 最右边的1的 右边所有的0变成了1, 不影响最左边. 我的代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4

sdut 2413:n a^o7 !(第三届山东省省赛原题,水题,字符串处理)

n a^o7 ! Time Limit: 1000MS Memory limit: 65536K 题目描述 All brave and intelligent fighters, next you will step into a distinctive battleground which is full of sweet and happiness. If you want to win the battle, you must do warm-up according to my inst

杭电(hdu)2053 Switch Game 水题

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13113    Accepted Submission(s): 7970 Problem Description There are many lamps in a line. All of them are off at first. A series of o

4.7-4.9补题+水题+高维前缀和

题目链接:51nod 1718 Cos的多项式  [数学] 题解: 2cosx=2cosx 2cos2x=(2cosx)^2-2 2cos3x=(2cosx)^3-3*(2cosx) 数归证明2cos(nx)能表示成关于2cosx的多项式,设为f(n) f(1)=x,f(2)=x^2-2(其中的x就是2cosx) 假设n=1~k时均成立(k>=3) 当n=k+1时 由cos((k+1)x)=cos(kx)cos(x)-sin(kx)sin(x) cos((k-1)x)=cos(kx)cos(x)

历年NOIP水题泛做

快noip了就乱做一下历年的noip题目咯.. noip2014 飞扬的小鸟 其实这道题并不是很难,但是就有点难搞 听说男神错了一个小时.. 就是$f_{i,j}$表示在第$i$个位置高度为$j$的时候最小点击次数 递推的话对于上升的情况只做一次,后面几次在后面再做.. #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namespace st

[ZPG TEST 114] 阿狸的英文名【水题】

1.      阿狸的英文名 阿狸最近想起一个英文名,于是他在网上查了很多个名字.他发现一些名字可以由两个不同的名字各取一部分得来,例如John(约翰)的前缀 "John"和Robinson(鲁滨逊)的后缀 "son" 连在一起就是Johnson. 现在他找到了两个喜欢的名字(名字可看作字符串),用A和B表示,他想知道取A的一个非空前缀和B的一个非空后缀,连接在一起能组成多少不同的字符串. 输入格式 输入两行,分别表示字符串A和B:字符串只包含小写英文字母. 输出格