题目链接:http://codeforces.com/problemset/problem/492/C

题目意思:给出 3 个整数:n,  r,  avg。然后有 n 行,每行有两个数:第 i 行有 ai 和 bi。表示如果写 bi 篇文章那么可以在 ai 这个分数上增加 1 分。可以增加好多次,但是前提是加完得到的分数不能超过 r。要使得 n 个exam 的分数平均分至少达到avg时需要写的最少文章是多少篇。

解决方法很简单,贪心即可。

   我们当然希望写的文章越少越好,所以先对文章从小到大排序。然后尽量往这个exam的分数加分,直到到达上限 r 。最后的情况是不需要到达 r 时,就把剩余的加上即可,就是代码中的else 循环的:ans += need * exam[i].b;

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; typedef __int64 LL;
const int maxn = 1e5 + ;
struct node
{
LL a, b;
}exam[maxn]; LL cmp(node x, node y)
{
if (x.b == y.b)
return x.a < y.a;
return x.b < y.b;
} int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
LL n, r, avg;
LL has, need, needed; while (scanf("%I64d%I64d%I64d", &n, &r, &avg) != EOF)
{
has = ;
for (__int64 i = ; i < n; i++)
{
scanf("%I64d%I64d", &exam[i].a, &exam[i].b);
has += exam[i].a;
} sort(exam, exam+n, cmp);
LL needed = 1ll * avg * n;
LL need = 1ll*needed - 1ll*has;
if (need <= )
printf("0\n");
else
{
LL ans = ;
for (LL i = ; i < n && need > ; i++)
{
if ((r-exam[i].a) <= need)
{
ans += (r-exam[i].a) * exam[i].b;
need -= r-exam[i].a;
}
else
{
ans += need * exam[i].b;
need -= need;
}
}
printf("%I64d\n", ans);
}
}
return ;
}

codeforces 492C. Vanya and Exams 解题报告的更多相关文章

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

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

  2. codeforces 492B. Vanya and Lanterns 解题报告

    题目链接:http://codeforces.com/problemset/problem/492/B #include <cstdio> #include <cstdlib> ...

  3. Codeforces Educational Round 92 赛后解题报告(A-G)

    Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...

  4. codeforces 476C.Dreamoon and Sums 解题报告

    题目链接:http://codeforces.com/problemset/problem/476/C 题目意思:给出两个数:a 和 b,要求算出 (x/b) / (x%b) == k,其中 k 的取 ...

  5. Codeforces Round #382 (Div. 2) 解题报告

    CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...

  6. codeforces 479C Exams 解题报告

    题目链接:http://codeforces.com/problemset/problem/479/C 题目意思:简单来说,就是有个人需要通过 n 门考试,每场考试他可以选择ai, bi 这其中一个时 ...

  7. codeforces 507B. Amr and Pins 解题报告

    题目链接:http://codeforces.com/problemset/problem/507/B 题目意思:给出圆的半径,以及圆心坐标和最终圆心要到达的坐标位置.问最少步数是多少.移动见下图.( ...

  8. codeforces 500B.New Year Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...

  9. codeforces B. Xenia and Ringroad 解题报告

    题目链接:http://codeforces.com/problemset/problem/339/B 题目理解不难,这句是解题的关键 In order to complete the i-th ta ...

随机推荐

  1. oracle中时间运算

    Oracle两个函数相减,默认得到的是天数,按日期格式,精准到响应的精度,如用sysdate(2015/12/7 10:17:52),时间差精确到秒. 在此基础上,oracle两个时间相减默认天数*2 ...

  2. 关于JS的几点TIPS

    作为前端基本工作每天都会用到JS...但是我们对JS真的都了解吗,或者说有什么tips是我们不知道的呢.. So..此文关于JS的几点tips..... 一:定时器(可传多个参数) 首先是一个一般的定 ...

  3. [设计模式] javascript 之 迭代子模式

    迭代子模式:定义 迭代子模式,又称游标模式,是一种用于对聚集进行顺序访问规则的模式,是一种行为模式:它用于提供对聚集对象的一种统一的访问接口,使客户能够在不了解聚集对象内部结构的情况对聚集对象进行访问 ...

  4. angularjs controller的两种写法

    在Angular中,Directive.Service.Filter.Controller都是以工厂方法的方式给出,而工厂方法的参数名对应着该工厂方法依赖的Service.如: app.control ...

  5. 遇到了IAR烧写程序出错,附解决办法The stack plug-in failed to set a breakpoint on "main"

    今天做无线串口调试的时候用IAR7.51往CC2530无线模块烧程序的时候遇到了问题: 先是下载过程中有许多警告,然后就是提示无法跳断点,找不到main方法,每次烧程序都出现: The stack p ...

  6. 2012Chengdu B (快速组合数)

    B - Candy Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

  7. CSS vertical-align 属性

    定义和用法 vertical-align 属性设置元素的垂直对齐方式.该属性定义行内元素的基线相对于该元素所在行的基线的垂直对齐

  8. Ubuntu 开机进入命令行模式

    1.修改配置 sudo vim /etc/default/grub 把 GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" 改为 GRUB_CMDL ...

  9. linux 之常见的好用命令

    参考网址:软件匠艺小组之第八期把命令行玩飞起来 1.如果想要将文件重定向到文件里,而又想看重定向的内容, tee命令 例如:ls | tee foot.txt 2.如果想要字母显示为大写独特的,命令: ...

  10. 【亲述】Uber容错设计与多机房容灾方案 - 高可用架构系列

    此文是根据赵磊在[QCON高可用架构群]中的分享内容整理而成.转载请事先联系赵磊及相关编辑. 赵磊,Uber高级工程师,08年上海交通大学毕业,曾就职于微软,后加入Facebook主要负责Messen ...