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,转载请注明来源
  • 相关阅读:
    树莓派笔记——了解与购买树莓派(1)
    SQLserver 备份和还原 失败
    lua coroutine
    lua for循环
    leetcode 46. 全排列
    sprintf、vsprintf、sprintf_s、vsprintf_s、_snprintf、_vsnprintf、snprintf、vsnprintf 函数辨析
    rapidxml的常见读写操作
    C++11 可变参数模板构造string列表
    Fedora 28 设置yum代理
    Linux命令计算文件中某一列的平均值
  • 原文地址:https://www.cnblogs.com/zhber/p/4136460.html
Copyright © 2011-2022 走看看