Codeforces Round #280 (Div. 2) C_html/css_WEB-ITnose

WBOY
Freigeben: 2016-06-24 11:53:03
Original
1062 Leute haben es durchsucht

题目:

C. Vanya and Exams

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 ai for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write bi essays. He can raise the exam grade multiple times.

What is the minimum number of essays that Vanya needs to write to get scholarship?

Input

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.

Each of the following n lines contains space-separated integers ai and bi (1?≤?ai?≤?r, 1?≤?bi?≤?106).

Output

In the first line print the minimum number of essays.

Sample test(s)

input

5 5 45 24 73 13 22 5
Nach dem Login kopieren

output

input

2 5 45 25 2
Nach dem Login kopieren

output

Note

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.

In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.


分析:贪心,优先bi最小的。然后注意下n*avg这里会爆LL就好了。

#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <vector>#include <queue>#include <stack>#include <cassert>#include <algorithm>#include <cmath>#include <set>#include <limits>#include <map>using namespace std;#define MIN(a, b) ((a)  (b) ? (a) : (b))#define F(i, n) for(int (i)=0;(i)=(t);--(i))#define REPOK(i, s, t, o) for(int (i)=(s);(i)::max();const double eps = 1e-10;const int INF = 0x7FFFFFFF;typedef long long LL;LL n, r, avg;struct node{    LL a, b;};int cmp(node x,node y){    return x.b<y.b main cin>> n >> r >> avg;    vector<node> v;    LL tma, tmb, sum = 0;    REP(i, 0, n-1)    {        cin >> tma >> tmb;        sum += tma;        v.push_back((node)        {            tma, tmb        });    }    sort(v.begin(), v.end(), cmp);    LL rest = avg*n-sum;    if (rest = can)        {            ans += v[i].b * can;            rest -= can;        }        else        {            ans += v[i].b * rest;            rest = 0;        }    }    cout   <br>   <br>   <p></p>    <br>  <p></p> </node></y.b></map></limits></set></cmath></algorithm></cassert></stack></queue></vector></cstring></cstdlib></cstdio></iostream>
Nach dem Login kopieren
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!