• Codeforces Round #280 (Div. 2) C. Vanya and Exams 贪心


    C. Vanya and Exams

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/492/problem/C

    Description

    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 nravg (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 ≤ r1 ≤ bi ≤ 106).

    Output

    In the first line print the minimum number of essays.

    Sample Input

    5 5 4
    5 2
    4 7
    3 1
    3 2
    2 5

    Sample Output

    4

    HINT

    题意

     有一个人有n门课程,每一门课程他最多获得r学分,他只要所有课程的平均学分有avg,他就可以获得奖学金

    每门课程,他已经获得了ai学分,剩下的每一个学分,都需要写bi篇论文才能得到

    然后问你,这个人最少写多少论文才能获得奖学金

    题解:

    贪心,我们选择bi最小的开始写论文,然后扫一遍就好了,直到学分够为止

    代码

    #include<iostream>
    #include<stdio.h>
    #include<algorithm>
    using namespace std;
    
    #define maxn 100005
    pair<long long,long long> p[maxn];
    int main()
    {
        int n;
        long long r,avg;
        scanf("%d%lld%lld",&n,&r,&avg);
        avg*=n;
        for(int i=0;i<n;i++)
        {
            scanf("%lld%lld",&p[i].second,&p[i].first);
            avg-=p[i].second;
            p[i].second = r - p[i].second;
        }
        sort(p,p+n);
        long long ans = 0;
        for(int i=0;i<n;i++)
        {
            if(avg<=0)break;
            if(p[i].second>=avg)
            {
                ans+=avg*p[i].first;
                break;
            }
            else
            {
                ans+=p[i].second*p[i].first;
                avg-=p[i].second;
            }
        }
        printf("%lld
    ",ans);
    }
  • 相关阅读:
    没有纳入spring管理的类如何注入spring管理的对象
    Servlet里面url-pattern的通配符*的使用规则
    【转】request和response的页面跳转传参
    Mybatis-Generator逆向生成Po,Mapper,XMLMAPPER(一)
    Sae上传war包找不到编译文件
    Maven配置中scope说明
    Spring配置中的classpath和classpath*的区别
    国内的ntp服务器
    U盘拷贝文件大小有限制吗?
    Genymotion安装教程
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4970408.html
Copyright © 2020-2023  润新知