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,转载请注明来源
  • 相关阅读:
    十个利用矩阵乘法解决的经典题目
    POJ-3070-Fibonacci
    java 正则表达式-忽略大小写与多行匹配
    【MM 非生产性物资采购】SAP实施项目中采购员在非生产性采购申请审批流中的角色安排(转)
    业务调研杂谈(转)
    重置报表输出选择
    【MM 配额管理】Quota Arrangement 配额管理(二)
    【MM 配额管理】Quota Arrangement 配额管理
    SDUST第十一次oj作业液晶显示问题
    如何在js代码中调用java,并将js的变量赋值给java
  • 原文地址:https://www.cnblogs.com/zhber/p/4136460.html
Copyright © 2011-2022 走看看