codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

762B.md (2245B)


      1 Source: https://codeforces.com/problemset/problem/762/B
      2 
      3 B. USB vs. PS/2
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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!
     22 
     23 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.
     24 
     25 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.
     26 
     27 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.
     28 
     29 Input
     30 
     31 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.
     32 
     33 The next line contains one integer *m* (0 ≤ *m* ≤ 3·105)  — the number of mouses in the price list.
     34 
     35 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.
     36 
     37 Output
     38 
     39 Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy.
     40 
     41 Example
     42 
     43 Input
     44 
     45 ```
     46 2 1 1  
     47 4  
     48 5 USB  
     49 6 PS/2  
     50 3 PS/2  
     51 7 PS/2
     52 ```
     53 
     54 Output
     55 
     56 ```
     57 3 14
     58 ```
     59 
     60 Note
     61 
     62 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.