【codeforces 762B】USB vs. PS/2
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis!
The computers bought for the room were different. Some of them had only USB ports, some — only PS/2 ports, and some had both options.
You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once.
You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy.
Input
The first line contains three integers a, b and c (0 ≤ a, b, c ≤ 105) — the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively.
The next line contains one integer m (0 ≤ m ≤ 3·105) — the number of mouses in the price list.
The next m lines each describe another mouse. The i-th line contains first integer vali (1 ≤ vali ≤ 109) — the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in.
Output
Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy.
Example
input
2 1 1
4
5 USB
6 PS/2
3 PS/2
7 PS/2
output
3 14
Note
In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports.
【题目链接】:http://codeforces.com/contest/762/problem/B
【题解】
/*
贪心。
对于两种类型的鼠标;
混在一起;按照价格升序排;
然后顺序枚举所有的鼠标;
对于遇到的鼠标;
(先遇到的鼠标一定要想法设法地把它买走,因为它肯定是比后面买的便宜)
如果是A类型且a>0,那么a--;如果a==0但是c>0那么就用那个c来买它
不然你那个c放在后面用的话,买到的鼠标肯定更贵!
如果是B类型且b>0,那么b--;如果b==0但是c>0那么同理肯定也要用那个
c来买它
这里a--,b--的情况肯定是正确的,因为同一种鼠标,a和b都只能买特定
的鼠标,你肯定先买便宜的嘛;
不然你留着a和b干嘛?买更贵的鼠标?
所以就优先使用a和b,而c则是在迫不得已的情况下再用;
如果买不走就跳过.
(原则就是,能买就买,因为前面都是最便宜的,最大限度地使每一个
a,b,c买到最便宜的鼠标)
*/
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define rei(x) scanf("%d",&x);
#define pb push_back
#define LL long long
#define se second
#define fi first
const string t1 = "USB";
const string t2 = "PS/2";
const int MAXN = 3e5+100;
int a,b,c,m,cnt = 0;
vector<pair <int,string> >dic;
LL ans = 0;
int main()
{
//freopen("F:\\rush.txt","r",stdin);
rei(a);rei(b);rei(c);
rei(m);
for (int i = 1;i <= m;i++)
{
LL price;string type;
cin >> price >> type;
dic.pb({price,type});
}
sort(dic.begin(),dic.end());
int len = dic.size();
for (int i = 0;i <= len-1;i++)
{
if (a && dic[i].se==t1)
a--;
else
if (b && dic[i].se == t2)
b--;
else
if (c)
c--;
else
continue;
cnt++;
ans+=dic[i].fi;
}
cout << cnt << ' '<<ans << endl;
return 0;
}
【codeforces 762B】USB vs. PS/2的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
- 【codeforces 515C】Drazil and Factorial
[题目链接]:http://codeforces.com/contest/515/problem/C [题意] 定义f(n)=n这个数各个位置上的数的阶乘的乘积; 给你a; 让你另外求一个不含0和1的 ...
- 【codeforces 515B】Drazil and His Happy Friends
[题目链接]:http://codeforces.com/contest/515/problem/B [题意] 第i天选择第i%n个男生,第i%m个女生,让他们一起去吃饭; 只要这一对中有一个人是开心 ...
随机推荐
- 廖雪峰Python总结3
1.模块简介 为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件中,这样每个文件包含的代码相对来说就比较少.一个.py文件就称之为一个模块(Module). 使用模块的好处: 提高了代码的可 ...
- 通过iOS 9 SFSafariViewController提供完整的Web浏览体验
http://www.cocoachina.com/ios/20150826/13157.html 本文由CocoaChina译者@涛声依旧-忆往昔翻译自tutsplus校对:BenBeng原文:iO ...
- NSString&NSMutableString常用操作梳理
http://www.cocoachina.com/ios/20150724/12722.html 上一篇梳理了NSArray&NSMutableArray常用操作,这次来梳理一下Object ...
- [CS]C#操作word 2016-04-17 18:30 1506人阅读 评论(35) 收藏
最近在做的项目已经改了好几版,最近这一版用到了word,当然不是直接使用word,而是使用第三方的ActiveX控件:dsoframer.ocx,此控件的使用和其他控件的使用流程没有任何区别,接下来介 ...
- 干货 | 解读MySQL 8.0新特性:Skip Scan Range
MySQL从8.0.13版本开始支持一种新的range scan方式,称为Loose Skip Scan.该特性由Facebook贡献.我们知道在之前的版本中,如果要使用到索引进行扫描,条件必须满足索 ...
- python 类与类之间的关系. 特殊成员
一.类与类之间的关系 1.依赖关系 在方法的参数位置把另一个类的对象作为参数进行传递 class Person: def play(self, tools): # 通过参数的传递把另一个类的对象传递进 ...
- 捕捉WPF应用程序中XAML代码解析异常
原文:捕捉WPF应用程序中XAML代码解析异常 由于WPF应用程序中XAML代码在很多时候是运行时加载处理的.比如DynamicResource,但是在编译或者运行的过程中,编写的XAML代码很可能有 ...
- SDWebImage源码解析之SDWebImageManager的注解
http://www.cocoachina.com/ios/20150612/12118.html 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ...
- 下载mysql document
wget -b -r -np -L -p https://dev.mysql.com/doc/refman/5.6/en/ 在下载时.有用到外部域名的图片或连接.如果需要同时下载就要用-H参数. wg ...
- MyEclipse2016项目内复制一个项目,如何更改项目的访问路径
在MyEclipse2010版本如果复制了一个项目,需要改项目的访问路径的话,可以选中项目右键,点开Properties,在顶部搜索web,就会出现如下内容,这是只需要在里面更改路径就可以了. 而在2 ...