zoukankan      html  css  js  c++  java
  • codeforces492C

    Vanya and Exams

     CodeForces - 492C 

    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 biessays. 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 nravg (1 ≤ n ≤ 1051 ≤ r ≤ 1091 ≤ 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 ≤ r1 ≤ bi ≤ 106).

    Output

    In the first line print the minimum number of essays.

    Examples

    Input
    5 5 4
    5 2
    4 7
    3 1
    3 2
    2 5
    Output
    4
    Input
    2 5 4
    5 2
    5 2
    Output
    0

    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.

    sol:挺明显的贪心,把便宜的都尽量升级的更高,一定是最优的,做到平均数够了为止

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    inline ll read()
    {
        ll s=0;
        bool f=0;
        char ch=' ';
        while(!isdigit(ch))
        {
            f|=(ch=='-'); ch=getchar();
        }
        while(isdigit(ch))
        {
            s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
        }
        return (f)?(-s):(s);
    }
    #define R(x) x=read()
    inline void write(ll x)
    {
        if(x<0)
        {
            putchar('-'); x=-x;
        }
        if(x<10)
        {
            putchar(x+'0');    return;
        }
        write(x/10);
        putchar((x%10)+'0');
        return;
    }
    #define W(x) write(x),putchar(' ')
    #define Wl(x) write(x),putchar('
    ')
    const int N=100005;
    ll n,Up,Yaoq;
    struct Fens
    {
        ll a,b;
    }Score[N];
    inline bool cmp_b(Fens p,Fens q)
    {
        return p.b<q.b;
    }
    int main()
    {
        int i;
        ll Sum=0,ans=0;
        R(n); R(Up); R(Yaoq);
        for(i=1;i<=n;i++)
        {
            R(Score[i].a); R(Score[i].b);
            Sum+=1ll*Score[i].a;
        }
        sort(Score+1,Score+n+1,cmp_b);
        i=0;
        while(Sum<1ll*n*Yaoq)
        {
            ll oo=min(1ll*(Up-Score[++i].a),1ll*(1ll*n*Yaoq-Sum));
            Sum+=1ll*oo;
            ans+=1ll*oo*Score[i].b;
        }
        Wl(ans);
        return 0;
    }
    /*
    input
    5 5 4
    5 2
    4 7
    3 1
    3 2
    2 5
    output
    4
    
    input
    2 5 4
    5 2
    5 2
    output
    0
    */
    View Code
  • 相关阅读:
    输出最大值 (10 分)
    对象数组初始化 (10 分)
    2018Final静态成员(黑名单)
    寻找回文子串(python)
    cpp-week_one-错题整理
    Python 读入多个整数
    C语言学习—strcpy()和strcat()
    javascript数学对象、自定义对象10.0
    javascript基础DOM对象6.2
    javascript基础DOM对象6.1
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/10651166.html
Copyright © 2011-2022 走看看