codeforces-scrape

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

33A.md (2721B)


      1 Source: https://codeforces.com/problemset/problem/33/A
      2 
      3 A. What is for dinner?
      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 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing".
     22 
     23 For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap).
     24 
     25 It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again.
     26 
     27 Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative.
     28 
     29 As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner.
     30 
     31 We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one.
     32 
     33 Input
     34 
     35 The first line contains three integers *n*, *m*, *k* (1 ≤ *m* ≤ *n* ≤ 1000, 0 ≤ *k* ≤ 106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1 ≤ *r* ≤ *m*) — index of the row, where belongs the corresponding tooth, and *c* (0 ≤ *c* ≤ 106) — its residual viability.
     36 
     37 It's guaranteed that each tooth row has positive amount of teeth.
     38 
     39 Output
     40 
     41 In the first line output the maximum amount of crucians that Valerie can consume for dinner.
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 4 3 18  
     49 2 3  
     50 1 2  
     51 3 6  
     52 2 3
     53 ```
     54 
     55 Output
     56 
     57 ```
     58 11
     59 ```
     60 
     61 Input
     62 
     63 ```
     64 2 2 13  
     65 1 13  
     66 2 12
     67 ```
     68 
     69 Output
     70 
     71 ```
     72 13
     73 ```