Lunch War with the Donkey CSU - 2084

Posted iwannabe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Lunch War with the Donkey CSU - 2084相关的知识,希望对你有一定的参考价值。

Jingze is a big figure in California State University for his stubbornness. Because of his new failure in the last CET-4, he has decided not to solve problems with English discription any more. In yesterday‘s warm-up contest,he protested to the organizing committee for the appearance of long English discription and threatened to eat all the bread of the contestants during coding. Undoubtedly, this behavior will seriously affect the entire competition. In order to help him get rid of English phobias, good-hearted seniors decided to help him regain his confidence with simple English problems. This problem is a gift that we gave to all contestants who are in the same boat with him.

In today‘s campus coding match, the contestants brought a variety of bread and milk, and each kind of bread and milk has its own deliciousness. Because Jingze can‘t just eat bread, he will also wipe out a carton of milk when eating a loaf of bread. If only bread or only milk leaves to have, his appetite will be zero. Since bread and milk are amazing lunch partners, different combinations bring different tastes. Everyone knows the deliciousness of some combination is defined to be its product. Of course the maximum sum of deliciousness is desired for Jingze while the minimum for us, although in both cases we seem to be disadvantaged.

In fact, the Lunch War will never happen and the following gif may be your live picture of today‘s early reading time and closing ceremony.

技术分享图片

Input

There are at most 20 test case.

For each test cases, you are given the number of kinds of bread and milk, N,?M for each and 1?≤?N,?M?≤?105.

In the following two lines are N?+?M positive integers denoting the deliciousness for each kind of bread and milk.

The deliciousness is guaranteed within 100.

Output

Two integers per line for each test: The maximum and minimum sum of deliciousness for Jingze and us.

Sample Input

1 4
23 
67 50 25 2 

10 6
95 30 2 18 96 6 5 52 99 89 
24 6 83 53 67 17 

Sample Output

1541 46
22884 2073

em 就是求上下组合起来乘积和最大值、最小值。
最大值很好说就是最大乘最大。
最小值的话,大值乘小值就是了

技术分享图片
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 
 5 using namespace std;
 6 const int maxn = 100005;
 7 int a[maxn];
 8 int b[maxn];
 9 
10 int main()
11 {
12     int n,m;
13     while(~scanf("%d%d",&n,&m))
14     {
15         for(int i=0; i<n; ++i)
16         {
17             scanf("%d",&a[i]);
18         }
19         for(int i=0; i<m; i++)
20         {
21             scanf("%d",&b[i]);
22         }
23         sort(a,a+n);
24         sort(b,b+m);
25         int minn = min(n,m);
26         int max_sun = 0, min_sum = 0;
27         for(int i=0; i<minn; ++i)
28         {
29             max_sun += a[n-i-1]*b[m-i-1];
30             min_sum += a[i]*b[minn-i-1];
31         }
32         printf("%d %d
",max_sun,min_sum);
33     }
34 }
View Code

 

 







以上是关于Lunch War with the Donkey CSU - 2084的主要内容,如果未能解决你的问题,请参考以下文章

oracle11g+tomcat 安装war包出错:IO 错误: The Network Adapter could not establish the connection

HDU 4005 The war Tarjan+dp

CodeForces 625B War of the Corporations

測试赛D - The War(有控制范围的贪心)

[CF98E]Help Shrek and Donkey

CF 249D Donkey and Start