CF762B.USB vs. PS/2

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

由于贝尔兰国立大学学生人数增加,决定配备一个新的计算机教室。你被委派购买鼠标,且需尽可能节省开支。毕竟,国家正处于危机之中!

为该教室购置的计算机各不相同:有些仅有 USB 接口,有些仅有 PS/2 接口,而有些则同时具备两种接口。

你已找到某家电脑商店的价格表。其中列出了 mm 个鼠标的单价及其所需连接的接口类型(USB 或 PS/2)。价格表中的每个鼠标最多只能购买一次。

你需要从给定的价格表中选购一组鼠标,使得所装配鼠标的计算机数量最大化(但无法保证能为所有计算机都装配鼠标);若存在多种方案可达到相同的最大装配数量,则在这些方案中选择总花费最小的一种。

输入格式

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 val__i (1 ≤ val__i ≤ 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.

第一行包含三个整数 aabbcc0a,b,c1050 \leq a,\,b,\,c \leq 10^5),分别表示仅具有 USB 接口的计算机数量、仅具有 PS/2 接口的计算机数量,以及同时具有两种接口的计算机数量。

第二行包含一个整数 mm0m31050 \leq m \leq 3\cdot10^5)—— 价格列表中鼠标的数量。

接下来的 mm 行每行描述一只鼠标。第 ii 行首先给出一个整数 vali\text{val}_i1vali1091 \leq \text{val}_i \leq 10^9)—— 第 ii 只鼠标的成本,随后给出该鼠标所需的接口类型(USBPS/2)。

输出格式

Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy.

输出两个由空格分隔的整数——已配备的计算机数量,以及你将购买的鼠标总成本。

输入输出样例

  • 输入#1

    2 1 1
    4
    5 USB
    6 PS/2
    3 PS/2
    7 PS/2

    输出#1

    3 14

说明/提示

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 接口的计算机配备一只 USB 鼠标,而两只 PS/2 鼠标则分别插入具有 PS/2 接口的计算机以及同时具有两种接口的计算机。

输入解题思路,AI测评打分。不知道怎么写?

首页