CF492C Vanya and Exams

有了Pascal题解,来一波C++题解呀qwq。。

简单的贪心题

按b[i]从小到大排序,一个一个学科写直到达到要求即可

#include<cstdio>
#include<algorithm>
using namespace std;
struct number {
long long a,b;
bool operator <(const number &x)const {
return b<x.b;
}
} a[100005];
long long ans,sum,n,r,ave;//不开long long最后一个点WA
int main() {
scanf("%lld%lld%lld",&n,&r,&ave),sum=n*ave;//总共需要的学分
for (int i=0; i<n; i++) scanf("%lld%lld",&a[i].a,&a[i].b),sum-=a[i].a;
if (sum<=0) {//若当前学分已大于大于所需,直接输出
puts("0");
return 0;
}
sort(a,a+n);//按a[i].b排序
for (int i=0; sum>0 && i<n; i++) {
ans+=a[i].b*min(sum,r-a[i].a);//每个学科的论文要么尽量写完(最多只能赚r-a[i].a个学分),要么写到达到要求即可
sum-=(r-a[i].a);//减去写论文所得学分
}
printf("%lld",ans);
}

题解 CF492C Vanya and Exams的更多相关文章

  1. cf492C Vanya and Exams

    C. Vanya and Exams time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. 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/pr ...

  3. Codeforces Round #280 (Div. 2)_C. Vanya and Exams

    C. Vanya and Exams time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  4. CodeForces 492C Vanya and Exams (贪心)

    C. Vanya and Exams time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. 题解-CF677D Vanya and Treasure

    CF677D Vanya and Treasure 有一个 \(n\times m\) 的矩阵 \(a(1\le a_{i,j}\le p)\),求从起点 \((1,1)\) 出发依次遍历值为 \(1 ...

  6. codeforces 492C. Vanya and Exams 解题报告

    题目链接:http://codeforces.com/problemset/problem/492/C 题目意思:给出 3 个整数:n,  r,  avg.然后有 n 行,每行有两个数:第 i 行有 ...

  7. Codeforces Round #280 (Div. 2) A B C 暴力 水 贪心

    A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  8. CodeForces Round #280 (Div.2)

    A. Vanya and Cubes 题意: 给你n个小方块,现在要搭一个金字塔,金字塔的第i层需要 个小方块,问这n个方块最多搭几层金字塔. 分析: 根据求和公式,有,按照规律直接加就行,直到超过n ...

  9. codeforces492C

    Vanya and Exams CodeForces - 492C Vanya wants to pass n exams and get the academic scholarship. He w ...

随机推荐

  1. AntDesign(React)学习-10 Dva 与后台数据交互

    明天正式在线办公没时间学习了,今天晚上再更新一篇, 代码提交一次:https://github.com/zhaogaojian/jgdemo 1.src下创建services目录 创建文件userSr ...

  2. Windows ThinPC 7 部署后续设置与本地化

    还原注销背景 %system32%\oobe\info\backgrounds 删除该目录下所有文件后变为wes7背景 24时制与非UNICODE字符乱码解决 Control Panel \ Regi ...

  3. hdu1716--全排列(dfs+有重复数字+输出格式)

    Ray又对数字的列产生了兴趣: 现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数.  Input每组数据占一行,代表四张卡片上的数字(0<=数字<=9 ...

  4. mybatis(五):源码分析 - 参数映射流程

  5. C语言预处理学习记录

    #include<stdio.h> #define LOCAL //无参宏 //条件编译 #ifdef LOCAL int a=1; #else int a=2; #endif #ifnd ...

  6. UES

    Spring-core-4.3.16 ObjectUtils.java public static boolean isEmpty(Object obj) { if (obj == null) { r ...

  7. Java-类的生命周期浅析

    简述:Java虚拟机为Java程序提供运行时环境,其中一项重要的任务就是管理类和对象的生命周期.类的生命周期.类的生命周期从类被加载.连接和初始化开始,到类被卸载结束.当类处于生命周期中时,它的二级制 ...

  8. 网络https工作原理

    网络https工作原理 待办 https://www.runoob.com/w3cnote/https-ssl-intro.html

  9. 域名网址在QQ微信被拦截怎么解决 如何样才能让被微信屏蔽的网址正常访问

    微信域名防封技术及微信域名被封解决方案. 微信又封杀我的域名了,微信域名被封怎么办? 做微信项目的兄弟们总跟我唠嗑抱怨,这个无可厚非, 微信如果不做屏蔽措施,微信里面传播传播的信息良莠不齐不治理, 肯 ...

  10. MySQL学习(五)事务隔离

    文章部分图片和总结来自参考资料,侵删 概述 MySQL的可重复读隔离级别,事务T启动的时候会创建一个视图read-view,之后事务T执行期间,即使有其他事务修改了数据,事务T看到的仍然跟在启动时看到 ...