• 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,转载请注明来源
  • 相关阅读:
    jQuery检测滚动条(scroll)是否到达底部
    sql group by
    hbm.xml 详解总结
    net.sf.json 时间格式的转化
    经典SQL语句大全
    HashTable
    in与exist , not in与not exist 的区别
    网页布局常用的一些命名规则和书写
    什么是SOA?
    sql之left join、right join、inner join的区别
  • 原文地址:https://www.cnblogs.com/zhber/p/4136460.html
Copyright © 2020-2023  润新知