codeforces-scrape

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

492C.md (1527B)


      1 Source: https://codeforces.com/problemset/problem/492/C
      2 
      3 C. Vanya and Exams
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Vanya wants to pass *n* exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least *avg*. The exam grade cannot exceed *r*. Vanya has passed the exams and got grade *a**i* for the *i*-th exam. To increase the grade for the *i*-th exam by 1 point, Vanya must write *b**i* essays. He can raise the exam grade multiple times.
     22 
     23 What is the minimum number of essays that Vanya needs to write to get scholarship?
     24 
     25 Input
     26 
     27 The first line contains three integers *n*, *r*, *avg* (1 ≤ *n* ≤ 105, 1 ≤ *r* ≤ 109, 1 ≤ *avg* ≤ *min*(*r*, 106)) — the number of exams, the maximum grade and the required grade point average, respectively.
     28 
     29 Each of the following *n* lines contains space-separated integers *a**i* and *b**i* (1 ≤ *a**i* ≤ *r*, 1 ≤ *b**i* ≤ 106).
     30 
     31 Output
     32 
     33 In the first line print the minimum number of essays.
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 5 5 4  
     41 5 2  
     42 4 7  
     43 3 1  
     44 3 2  
     45 2 5
     46 ```
     47 
     48 Output
     49 
     50 ```
     51 4
     52 ```
     53 
     54 Input
     55 
     56 ```
     57 2 5 4  
     58 5 2  
     59 5 2
     60 ```
     61 
     62 Output
     63 
     64 ```
     65 0
     66 ```
     67 
     68 Note
     69 
     70 In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point.
     71 
     72 In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.