CodeForces 492C Vanya and Exams
来源:互联网 发布:海拉淘宝店 编辑:程序博客网 时间:2024/05/16 15:53
CodeForces 492C Vanya and Exams
CodeForces 492C
题目大意:
有一位同学要参加N门科目的考试,每门科目的满分固定,现在这位同学为了拿到奖学金需要达到平均分S,这就需要它在原来的基础上对某些科目的分数进行提升,然后提升每门科目需要做Ai个测试,于是希望能够做尽量少的测试能够使得分数达到平均分。
解题思路:
将所有的科目按照对应的测试数进行排序,每次都选择测试数小的来进行分数的提升,直到到达平均分为止。
代码:
#include <cstdio>#include <algorithm>using namespace std;typedef long long ll;const int maxn = 1e5 + 5;struct exam { int a, b;}e[maxn];int cmp(const exam& e1, const exam& e2) { return e1.b < e2.b; }int N, R, AVG;int main () { ll gap, ans; while (scanf("%d%d%d", &N, &R, &AVG) != EOF){ ans = gap = 0; for (int i = 0; i < N; i++) { scanf ("%d%d", &e[i].a, &e[i].b); gap += e[i].a - AVG; } if (gap >= 0) { printf ("%lld\n", ans); continue; } sort(e, e + N, cmp); for (int i = 0; i < N; i++) { if (gap + (R - e[i].a) <= 0) { ans += (ll)e[i].b * (R - e[i].a); gap += (R - e[i].a); } else { ans -= (ll)e[i].b * gap; gap = 0; } if (gap == 0) break; } printf ("%lld\n", ans); } return 0;}
0 0
- Codeforces 492C Vanya and Exams(贪心)
- CodeForces 492C Vanya and Exams
- Codeforces-492C-Vanya and Exams
- Codeforces 492C Vanya and Exams【贪心】
- 492C - Vanya and Exams
- CodeForces 492C Vanya and Exams(贪心)
- C. Vanya and Exams
- codeforce 492C. Vanya and Exams
- Codeforces Round #280 (Div. 2) C. Vanya and Exams
- CF 280C. Vanya and Exams(div2)
- Codeforces Round #280 (Div. 2)---C. Vanya and Exams (贪心)
- Codeforces Round #280 (Div. 2)C. Vanya and Exams(贪心)
- Vanya and Exams
- Codeforces Round #280 (Div. 2)_C. Vanya and Exams
- Codeforces #308 C. Vanya and Scales
- Codeforces 552C Vanya and Scales
- codeforces 552 C Vanya and Scales
- [CodeForces 552C]Vanya and Scales[math]
- sdf
- Open CASCADE Technology: IGES Support
- [CF 343E]Pumping Stations解题报告
- Android--app包中的fragment和v4包中的fragment的使用的区别
- Project Euler:Problem 42 Coded triangle numbers
- CodeForces 492C Vanya and Exams
- XE6 IntraWeb.v14.0.32安装及破解指南
- 根据网络包内容过滤
- 浅析人脸检测之Haar分类器方法:Haar特征、积分图、 AdaBoost 、级联
- iOS 怎么让tableView滑动最底端
- mysql数据库锁机制
- Index logic in MySQL& B- tree algorithm
- shell基本命令
- 【PAT 乙级(Basic Level)】分A+B