AtCoder Contest 229-C-Cheese
Problem Statement
Takahashi, who works for a pizza restaurant, is making a delicious cheese pizza for staff meals.
There are NN kinds of cheese in front of him.
The deliciousness of the ii-th kind of cheese is A_iAi per gram, and B_iBi grams of this cheese are available.
The deliciousness of the pizza will be the total deliciousness of cheese he puts on top of the pizza.
However, using too much cheese would make his boss angry, so the pizza can have at most WW grams of cheese on top of it.
Under this condition, find the maximum possible deliciousness of the pizza.Constraints
- All values in input are integers.
- 1 \le N \le 3 \times 10^51≤N≤3×105
- 1 \le W \le 3 \times 10^81≤W≤3×108
- 1 \le A_i \le 10^91≤Ai≤109
- 1 \le B_i \le 10001≤Bi≤1000
Input
Input is given from Standard Input in the following format:
NN WW A_1A1 B_1B1 A_2A2 B_2B2 \vdots⋮ A_NAN B_NBNOutput
Print the answer as an integer.
Sample Input 1 Copy
Copy
3 5 3 1 4 2 2 3Sample Output 1 Copy
Copy
15The optimal choice is to use 11 gram of cheese of the first kind, 22 grams of the second kind, and 22 grams of the third kind.
The pizza will have a deliciousness of 1515.
Sample Input 2 Copy
Copy
4 100 6 2 1 5 3 9 8 7Sample Output 2 Copy
Copy
100There may be less than WW grams of cheese in total.
Sample Input 3 Copy
Copy
10 3141 314944731 649 140276783 228 578012421 809 878510647 519 925326537 943 337666726 611 879137070 306 87808915 39 756059990 244 228622672 291Sample Output 3 Copy
Copy
2357689932073
题目类型:贪心
题目目标:寻找Wgram内N种芝士可以组合出最大的美味度
注意点:注意一下数据范围,3+5+9 = 17, 10e17 ,long long
解题思路:1)一开始认为是容量为1的多重背包,然后RE了
2)后来发现有更简单的方法;
1)每种芝士只有数量和美味度两种性质,pair就可以了。读入。
2)排序,自己写cmp也可以,sort+reverse()也可以。
3)在容量允许的情况下,把当前美味度最大的芝士全放入,若容量不够,把剩余的容量都用来放当前美味度最大的芝士。容量为0,跳出输出。
AC代码:
#include <bits/stdc++.h>
#define rep(x, a, b) for(int x=a; x<=b; x++)
#define inf 0x3f3f3f3f
#define ll long long
using namespace std;
const int N= 3e5+10;
int n, w;
bool cmp(pair< ll, ll > a, pair< ll, ll > b)
{return a.first > b.first;
}
int main()
{ll ans = 0;scanf("%d%d", &n,&w);vector< pair< ll, ll > > v(n);rep(i, 0, n-1)cin>>v[i].first>>v[i].second;sort(v.begin(), v.end(), cmp);rep(i, 0, n-1){if(!w) break;if(w - v[i].second >= 0){w -= v[i].second;ans += v[i].first*v[i].second;}else if(w < v[i].second){ans += v[i].first*w;w = 0;}}cout<<ans;return 0;
}
AtCoder Contest 229-C-Cheese相关推荐
- NEC Programming Contest 2021(AtCoder Beginner Contest 229) B - Hard Calculation
题目链接:B - Hard Calculation (atcoder.jp) Problem Statement You are given positive integers A and B. Le ...
- NEC Programming Contest 2021 (AtCoder Beginner Contest 229)
终于开始补提了 重点 : C, E的倒着算, F的染色,G的相邻的转换: B - Hard Calculation #include <iostream> #include <alg ...
- F - Make Bipartite(dp)
F - Make Bipartite(dp) 考虑对于第iii点,显然它的贡献只与i−1i-1i−1和000有关. 不失一般性,不妨设000为红色. 然后我们进行dpdpdp,为了避免后效性,我们先断 ...
- 2022年湖南工学院第九届大学生计算机程序设计竞赛题解
A题 模拟只会猜题意 来源:AtCoder Beginner Contest 195 E - Lucky 7 Battle 链接:E - Lucky 7 Battle 考察:dp 难度:黄题 B题 贪 ...
- Article List
在洛谷博客上会发布一些零碎的题目的题解,就不放在此目录了. 链接:文章列表 - MC菜鸟 的博客 - 洛谷博客 CSP-J 2022题解 AtCoder Contest ABC277 YACS 11 ...
- 【每日亿题#12】AtCoder Grand Contest 021 (A ~ F)全部题解
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 文章目录 AtCoder Grand Contest 021 题解 A. Digit Sum 2 B. ...
- AtCoder Beginner Contest 202 D - aab aba baa(组合计数,字典序)
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Problem 有 AAA 和 aaa,BBB 个 bbb ,可以使用这 A+BA+BA+B 个字符任 ...
- AtCoder Beginner Contest 197 题解(A ~ F)
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Rotate B - Visibility C - ORXOR D - Opposite ...
- AtCoder Beginner Contest 198 (A ~ F)题解
目录 A. Div B. Palindrome with leading zeros C. Compass Walking D. Send More Money E. Unique Color F. ...
最新文章
- pytorch注意事项
- mysql 查看索引 命令_MySQL命令篇之库、表、索引、用户、视图及SELECT查询
- 樊登读书分享ppt_樊登读书精华分享-《分手后,成为更好的自己》
- PostgreSQL 9.6 IO Hang问题浅析与优化
- android 头像存储,安卓裁剪上传保存头像
- python输出到指定文件夹_python实现指定文件夹下的指定文件移动到指定位置
- 拓端tecdat|R语言Fisher检验探究地区间公寓价格的关系
- 这些PHP考点虽然简单基础,但是很重点
- oracle不提交事务语句,oracle查找客户端未提交的事务语句
- java socket编程—单客户端与服务器通信
- vue实现echarts地图展示省份数据
- android listview表格分页显示,android实现listview分页的方法
- 关于Jabber客户端
- 计算机视觉项目实战-基于特征点匹配的图像拼接
- 十六国帝王纪元表-20170722
- 理论学习-协议栈学习-CANopen协议梳理
- 奇异值分解的几何原理
- SS P5装备毕业装备
- pandas数据分析常用的一些方法
- Latex表格线宽修改方法以及内容左对齐。