URAL 1788 On the Benefits of Umbrellas
来源:互联网 发布:淘宝卖家衣服轮播图 编辑:程序博客网 时间:2024/05/18 20:36
1788. On the Benefits of Umbrellas
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
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, …, gn separated 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
2 41 10010 8 6 4
19
Problem Author: Sofia Tekhazheva, prepared by Denis Dublennykh
Problem Source: Ural Regional School Programming Contest 2010
Problem Source: Ural Regional School Programming Contest 2010
这是一道贪心题,注意贪心的方法即可;
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int MAXN=110;bool cmp(const int &a,const int &b){ return a>b;}int G[MAXN],B[MAXN];int Gsum[MAXN],Bsum[MAXN];int main(){int n,m;scanf("%d%d",&n,&m); for(int i=0;i<n;i++){ scanf("%d",&G[i]); } for(int i=0;i<m;i++){ scanf("%d",&B[i]); } memset(Gsum,0,sizeof(Gsum)); memset(Bsum,0,sizeof(Bsum)); sort(G,G+n,cmp); sort(B,B+m,cmp); for(int i=n-1;i>=0;--i) Gsum[i]=Gsum[i+1]+G[i]; for(int i=m-1;i>=0;--i) Bsum[i]=Bsum[i+1]+B[i]; int ans=0x3f3f3f3f; int sum; for(int i=0;i<=min(m,n);++i) { sum=Gsum[i]+Bsum[i]*i; ans=min(ans,sum); }cout<<ans<<endl;return 0;}
0 0
- URAL 1788On the Benefits of Umbrellas
- URAL 1788 On the Benefits of Umbrellas
- URAL - 1788 On the Benefits of Umbrellas(水题)
- 01. The Benefits of JanusGraph
- Benefits of Using the .NET Framework
- The Benefits of Hiring a Janitorial Service_111
- Reap the benefits of document style Web services
- Goodbye, Silos: The Benefits of Converged Data Centers
- What are the benefits of PreparedStatement over Statement
- book1 unit2 after-class reading 2 : The Benefits of Forgetting
- Benefits of Internet EDI
- Benefits of Code Refactoring
- Benefits of software localization
- Business analysis and SOA part 1 of 6: The benefits of business services [by Thomas Erl]
- Beautiful Code {16. The Linux Kernel Driver Model: The Benefits of Working Together}
- Beautiful Code {16. The Linux Kernel Driver Model: The Benefits of Working Together}
- ural 1207. Median on the Plane
- URAL 1207 Median on the Plane
- 字符串相似算法 Jaro-Winkler Distance (string distance)
- sublime—angularjs plugin—linux—web—cbpm
- Python——Requests
- 欢迎使用CSDN-markdown编辑器
- Android 删除没有用到的资源
- URAL 1788 On the Benefits of Umbrellas
- Yeoman:Web 应用开发流程与工具—AngularJS—Bootstrap—js
- 汇编语言小知识点
- kindeditor上传图片时候,上传成功了,但是页面上却提示失败
- 美国罗斯福纪念公园墙上刻着的一段总统名言
- android 自动更新APP版本,并使用ProgressDialog显示进度
- 新建target后info.plist的路径关联指向问题
- 搜索算法基础之Oil Deposits
- Android屏幕分辨率的问题,dp,px,density等概念