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. redis五大数据类型以及常用操作命令

    Redis的五大数据类型 String(字符串) string是redis最基本的类型,你可以理解成与Memcached一模一样的类型,一个key对应一个value.string类型是二进制安全的.意 ...

  2. TCL 字典

    https://www.yiibai.com/tcl/tcl_dictionary.html 词典是用于值映射到建的布置. 常规字典的语法: dict  set dictname key value ...

  3. bat文件一键运行python自动化脚本

    目标:建立一个双击即可运行自动化脚本的机制,而不用每次运行编译器,方便测试人员用户体验. 方法: 1. 将所有代码打包成exe文件,但一旦修改,又要重新打包. 2. 将运行代码写成bat文件,双击即执 ...

  4. C++ log4cpp使用(转)

    参考文章: 1.常用C++库(1)日志库 https://blog.csdn.net/qilimi1053620912/article/details/87378707 2.一步步入门log4cpp  ...

  5. jQuery实现隔行变色、悬停变色 ( CSS3伪类选择器:nth-child() )

    <title>实现隔行变色</title> <script src="Js/jquery-1.8.0.min.js" type="text/ ...

  6. [Codechef SSTORY] A Story with Strings - 后缀数组,二分

    [Codechef SSTORY] A Story with Strings Description 给定两个字符串,求它们的最长公共子串.如果解不唯一,输出最先在第二个字符串中出现的那个. Solu ...

  7. Python实现共享内存通信方式

    创建共享内存python文件: import mmap import contextlib import time with contextlib.closing(mmap.mmap(-1, 100, ...

  8. 三分钟快速上手TensorFlow 2.0 (下)——模型的部署 、大规模训练、加速

    前文:三分钟快速上手TensorFlow 2.0 (中)——常用模块和模型的部署 TensorFlow 模型导出 使用 SavedModel 完整导出模型 不仅包含参数的权值,还包含计算的流程(即计算 ...

  9. C语言数据结构——第四章 串

    四.串 4.1-串的基本概念 串的定义 串是由数字.字母或其他字符组成的有限序列,一般记为 StringName = “a[0]a[1]a[2]···a[i]···a[n-1]”(n>0,0&l ...

  10. git中全局设置用户名、邮箱

    1.查看git配置信息:git config --list (可以查看所有的配置信息) 2.查看git用户名:git config user.name 3.查看邮箱配置:git config user ...