国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

CodeForces - 762B(貪心)

2019-11-08 18:23:46
字體:
供稿:網(wǎng)友

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.


一部分電腦只能用usb的一部分電腦只能用PS/2的,還有一部分電腦都能用,先排序后貪心,先處理非通用的,然后處理通用的。

#include<iostream>#include<stdio.h>#include<algorithm>#include<string.h>#include<string>using namespace std;int a,b,c,m;int pa[300005],pb[300005];int main(){ string str; int num; scanf("%d%d%d",&a,&b,&c); int numa=0,numb=0; scanf("%d",&m); for(int i=0;i<m;i++){ cin>>num>>str; if(str=="USB"){pa[numa++]=num;} else{pb[numb++]=num;} } sort(pa,pa+numa); sort(pb,pb+numb); int i,j; long long ans=0,money=0; for(i=0;i<numa&&i<a;i++){ money+=pa[i];ans++; } for(j=0;j<numb&&j<b;j++){ money+=pb[j];ans++; } int cnt=0; while((i<numa||j<numb)&&cnt<c){ if(i==numa){money+=pb[j++];ans++;cnt++;} else if(j==numb){money+=pa[i++];ans++;cnt++;} else{ if(pa[i]<pb[j]){money+=pa[i++];ans++;cnt++;} else{money+=pb[j++];ans++;cnt++;} } } cout<<ans<<' '<<money;return 0;}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 延庆县| 蒲江县| 丰台区| 津南区| 昌都县| 工布江达县| 乐昌市| 吉水县| 泸定县| 克东县| 从化市| 保定市| 西丰县| 鹤岗市| 巍山| 边坝县| 平原县| 洞头县| 辽宁省| 九龙城区| 天柱县| 土默特右旗| 汝州市| 普陀区| 平昌县| 乌兰察布市| 河北省| 游戏| 东阳市| 南岸区| 芦山县| 北流市| 凤城市| 于田县| 沧源| 霍邱县| 临沧市| 阿克陶县| 秭归县| 阿克苏市| 金寨县|