zoukankan      html  css  js  c++  java
  • cf492C Vanya and Exams

    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 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 test(s)
    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.

    唉其实就是贪心完排个序

    结果没有加个(LL)就被x掉了

    不开心

    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<algorithm>
    #include<cmath>
    #include<queue>
    #include<deque>
    #include<set>
    #include<map>
    #include<ctime>
    #define LL long long
    #define inf 0x7ffffff
    #define pa pair<int,int>
    #define pi 3.1415926535897932384626433832795028841971
    using namespace std;
    inline LL read()
    {
        LL x=0,f=1;char ch=getchar();
        while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
        while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
        return x*f;
    }
    int n,m,k;
    LL tot,ans;
    struct cla{
    	int a,b;
    }c[1000010];
    bool operator <(cla a,cla b)
    {return a.b<b.b;}
    int main()
    {
    	n=read();m=read();k=read();
    	for (int i=1;i<=n;i++)
    	{
    		
    		c[i].a=read();c[i].b=read();
    		tot+=c[i].a;
    		c[i].a=m-c[i].a;
    	}
    	tot=(LL)n*k-tot;
    	if (tot<=0)
    	{
    		printf("0
    ");
    		return 0;
    	}
    	sort(c+1,c+n+1);
    	for (int i=1;i<=n;i++)
    	{
    		if (!tot)break;
    		if (c[i].a<=tot)
    		{
    			tot-=c[i].a;
    			ans+=(LL)c[i].b*c[i].a;
    		}else
    		if (c[i].a>tot)
    		{
    			ans+=(LL)tot*c[i].b;
    			tot=0;
    		}
    	}
    	printf("%lld
    ",ans);
    }
    
    ——by zhber,转载请注明来源
  • 相关阅读:
    Python 实现红绿灯
    ELK使用1-Elasticsearch使用
    CF Educational Codeforces Round 21
    Codeforces Round #408 (Div. 2)
    2017年 湘潭邀请赛(湖南)or 江苏省赛
    Tinkoff Challenge
    欧几里德算法与扩展欧几里德算法
    operator的各种问题
    树状数组 Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains
    Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) D. Field expansion
  • 原文地址:https://www.cnblogs.com/zhber/p/4136460.html
Copyright © 2011-2022 走看看