URAL - 1788 On the Benefits of Umbrellas(水题)
2015-04-20 02:05
381 查看
On the Benefits of Umbrellas
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
1<=n,m<=100,于是直接枚举就好了。
Time Limit: 1000MS | Memory Limit: 65536KB | 64bit IO Format: %I64d & %I64u |
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
input | output |
---|---|
2 4 1 100 10 8 6 4 | 19 |
#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
- URAL 1788 On the Benefits of Umbrellas
- Leetcode--->Given n points on a 2D plane, find the maximum number of points that lie on the same str
- Access Denied: Either the SOM service on the machine is not started or the user attempting this connection is not a member of th
- Changing the Output Voltage of a Switching Regulator on the Fly
- Codeforces Beta Round #92 (Div. 2) / 124A The number of positions 【简单模拟】【水题】
- the usage of vi on mac
- URAL 1021 Sacrament of the Sum
- The premature demise of Windows 8 on ARM, courtesy of Intel’s Medfield
- BUG: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
- ORA-01039: insufficient privileges on underlying objects of the view
- [INS-41107]eth0 selected for one or more of the public or private interfaces is not on a shared subn
- This compilation unit is not on the build path of java project 错误
- What is the use of the res/values/public.xml file on Android?
- What are the benefits of PreparedStatement over Statement
- POJ 3100 Root of the Problem(我的水题之路——取A^N最接近B的A)
- RFC3117 - On the Design of Application Protocols
- ural 1207. Median on the Plane
- HDU 4727 The Number Off of FFF (水题)
- 62.You are in the middle of a transaction updating a very important table. The machine on which a da