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. 执行python程序的方式

    1.交互器 程序不能永久保存 主要用于简单的语法测试相关 2.文件执行

  2. Copy Paste DWG to older 3ds Max

    Hi, This is quick tutorial: how to install Auto Cad scripts to be able to copy from newer Auto Cad t ...

  3. 无缘诺贝尔奖的George Dantzig——线性规划之父

    无缘诺贝尔奖的George Dantzig——线性规划之父 王军强,2012年11月2日 “线性规划之父”的George Dantzig,与“计算机之父”.“博弈论之父”John Von Neuman ...

  4. 《深入理解Java虚拟机》读书笔记二

    第三章 垃圾收集器与内存分配策略 1.判断对象是否已死 引用计数法: 给对象添加一个引用计数器,每当有一个地方引用它时,计数器值就加1,每当引用失效时,计数器值就减1. 任何时刻计数器为0的对象就是不 ...

  5. NAND FLASH驱动框架以及程序实现

    1.NAND FLASH的硬件连接: 实验用的NAND FLASH芯片为K9F2G08U0C,它是三星公司的存储芯片,它的大小为256M.它的接线图如下所示: 它的每个引脚的分别为LDATA0-LDA ...

  6. Codeforces Round #613 (Div. 2) A-E简要题解

    contest链接:https://codeforces.com/contest/1285 A. Mezo Playing Zoma 签到 #include<iostream> #incl ...

  7. POJ3273 Monthly Expense (二分最小化花费)

    链接:http://poj.org/problem?id=3273 题意:FJ想把n天分成m组,每组是连续的,同一组的花费加起来算,求所分组情况中最高花费的最低值 思路:二分答案.二分整数范围内的花费 ...

  8. C++学习网站总结

    http://club.topsage.com/thread-361504-1-1.html Visual C++ (VC) / MFC 电子书下载: Visual C++ 2008 入门经典 (中文 ...

  9. html5 标准文档结构

    <!DOCTYPE html> <html lang="zh-cmn-Hans"> <head> <meta charset=" ...

  10. 字节流和字符流的read方法

    字节流和字符流的read方法 public class Test { public void fileOutput() throws Exception { File file = new File( ...