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. IntelliJ IDEA 2019.1.3 最新破解教程【最强 可用至2099年】

    本文包括最新[2019.1.2]安装 和[2018.3.2](推荐)安装 ①IntelliJ IDEA 2018.3.2安装永久安装[最强]  一. 在官网下载IDEA安装包  链接:https:// ...

  2. [CF1220C] Substring Game in the Lesson - 博弈论

    [CF1220C] Description 给定一个字符串 \(S\) , 同时维护一个区间 \([l,r]\) .轮流操作,每次可以扩展到一个新区间使得原区间是新区间的真子区间,并且字典序更小,不能 ...

  3. Linux 查看是否安装 oracle

    查看是否用 oracle 的进程 ps -ef | grep ora 一般安装 oracle ,默认会有 oracle 的用户. id oracle

  4. django 完成登录功能

    啃了几天文档,感觉能理解了这个框架,但是真的下手的时候真的不知道从何开始. orm即Object-Relationl Mapping,看这名字就是操作数据库的,用过ssm,不过django操作数据库是 ...

  5. Itext相关知识

    最近需求用到office和pdf相关知识,office使用poi操作的,pdf则使用Itext操作 Itext官网: http://itextpdf.com/ Itext7相关使用示例:https:/ ...

  6. SpringBoot整合WEB开发--(三)文件上传

    文件上传: Java中文件上传一共涉及到两个组件,CommonsMultipartResolver和StandardServletMultipartResolver,其中CommonsMultipar ...

  7. Photoshop——APP设计规范

    随着Android和iOS语言的兴起,能够在手机上运行的APP软件已经成为了目前移动应用技术的焦点,APP的UI设计随之也越来越受到重视. 用户的需求不断增加,技术也在不断的更新,UI设计也越来越被重 ...

  8. iframe宽高自适应

    iframe子页面结尾添加本script iframe子页面结尾添加本script <script type="text/javascript">         fu ...

  9. 百度地图使用http ,https

    通过判断http或https if($_SERVER['REQUEST_SCHEME']=='http'){ return true; }else{ return false; } https网站使用 ...

  10. [刷题] Leetcode算法 (2020-2-27)

    1.最后一个单词的长度(很简单) 题目: 给定一个仅包含大小写字母和空格 ' ' 的字符串 s,返回其最后一个单词的长度. 如果字符串从左向右滚动显示,那么最后一个单词就是最后出现的单词. 如果不存在 ...