题解 CF492C Vanya and Exams
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的更多相关文章
- cf492C Vanya and Exams
C. Vanya and Exams time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 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 ...
- 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 ...
- CodeForces 492C Vanya and Exams (贪心)
C. Vanya and Exams time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 题解-CF677D Vanya and Treasure
CF677D Vanya and Treasure 有一个 \(n\times m\) 的矩阵 \(a(1\le a_{i,j}\le p)\),求从起点 \((1,1)\) 出发依次遍历值为 \(1 ...
- codeforces 492C. Vanya and Exams 解题报告
题目链接:http://codeforces.com/problemset/problem/492/C 题目意思:给出 3 个整数:n, r, avg.然后有 n 行,每行有两个数:第 i 行有 ...
- 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 ...
- CodeForces Round #280 (Div.2)
A. Vanya and Cubes 题意: 给你n个小方块,现在要搭一个金字塔,金字塔的第i层需要 个小方块,问这n个方块最多搭几层金字塔. 分析: 根据求和公式,有,按照规律直接加就行,直到超过n ...
- codeforces492C
Vanya and Exams CodeForces - 492C Vanya wants to pass n exams and get the academic scholarship. He w ...
随机推荐
- Mvc-WebAPI特性路由(自定义路由)Demo
Demo由VS2017编写. 1.先建一个WebApi项目 2.WebApiConfig.cs需要注册特性路由,config.MapHttpAttributeRoutes(); 3.项目默认有2个Co ...
- Mysql多实例数据库安装应用
第1章 MySQL多实例数据库企业级应用实践 1.1 MySQL多实例介绍 前文已经讲了为什么选择MySQL数据库,以及MySQL数据库在Linux系统下的多种安装方式,同时以单实例讲解了编译方式安装 ...
- vue使用kkfileview文件预览功能
1.环境要求: java 1.8+ 2.部署运行: 本机以及虚拟机上运行: 1.从https://gitee.com/kekingcn/file-online-preview/releases地址下载 ...
- django 版本 对应pyhton版本
对应关系
- 关于gets读入因为缓冲区出现的问题
今天被一个同学丢了代码求debug 然后发现bug挺有意思的,稍微记录一下 首先我们读入的东西都会被丢进缓冲区等待接收,比如abc\n,如果你使用scanf读入的话,它在读入到\n的时候就会提取它需要 ...
- 题解【洛谷P1725】琪露诺
题面 典型的单调队列优化\(\text{DP}\)题. 不难想到设\(dp_i\)表示以\(i\)结尾能得到的最大冰冻指数. 这样设的转移方程也很简单:\(dp_i=\max\left\{ dp_j+ ...
- 题解【Vijos1159】岳麓山上打水
题面 迭代加深搜索模板题. 注意开始时要先对桶的容量从小到大排序. 达到搜索层数时使用完全背包\(\text{check}\)即可. 具体实现参考代码. #include <bits/stdc+ ...
- 【Python】浮点数用科学计数法表示
- 【转载】Hibernate关系映射
1. 单向一对一关联映射(one-to-one): 两个对象之间一对的关系,例如:Person(人)-IdCard(身份证) 有两种策略可以实现一对一的关联映射: *主键关联:即让两个对 ...
- JavaScript对象之get/set方法
我们可以重写js对象属性的get和set方法. 从上图我们可以看出set和get的语法. 上图则是使用set和get方法对对象的属性进行了输入校验. 从上图可得若对象的原型链上具有不可配置的同名属性( ...