链接:https://ac.nowcoder.com/acm/contest/332/C

题意:

小B想给她的新项链染色。
现在有m种颜色,对于第i种颜色,小B有a_i单位的颜料,每单位颜料可以染项链的一个珠子;
同时,小B对于第i种颜色的喜爱度为b_i。
已知项链有n个珠子,求染色后每个珠子的颜色的喜爱度之和的最大值。
(每个珠子只能至多被染一次,不被染色则喜爱度为0)

思路:

贪心即可。

代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e5 + 10; struct Node
{
int _a;
int _b;
bool operator < (const Node & that) const {
return this->_b > that._b;
}
}node[MAXN]; int main()
{
int n, m;
LL all = 0;
scanf("%d%d",&n,&m);
for (int i = 1;i <= m;i++)
cin >> node[i]._a,all += node[i]._a;
for (int i = 1;i <= m;i++)
cin >> node[i]._b;
sort(node + 1, node + 1 + m);
LL res = 0;
int w = 1;
while (n > 0 && all > 0)
{
if (n >= node[w]._a)
{
res += node[w]._a * node[w]._b;
n -= node[w]._a;
all -= node[w]._a;
w++;
}
else
{
res += n * node[w]._b;
break;
}
}
cout << res << endl; return 0;
}

最新文章

  1. Python的高级特性9:蹩脚的多态
  2. background-size扫盲
  3. Java开发中经典的小实例-(打印九九乘法表)
  4. 【Android】Spinner使用
  5. [学习嵌入式开发板]iTOP-4412实现NFS网络文件系统
  6. Qt环境搭建(Visual Studio)
  7. http header详解
  8. HW2.4
  9. jsp当参数为空的时候默认显示值
  10. linux提取锁和信号灯经常使用
  11. PDO详解
  12. php数据分页显示基础
  13. JMeter接口返回数组键值对校验方法
  14. ArcGIS API for JavaScript 4.2学习笔记[16] 弹窗自定义功能按钮及为要素自定义按钮(第五章完结)
  15. multiWriter.go
  16. java变量和javascript变量之间的传递
  17. [dart学习]第一篇:windows下安装配置dart编译环境,写出helloworld
  18. 关于TCP和MQTT之间的转换(转载)
  19. go基础系列:简介
  20. mybatis配置文件详解

热门文章

  1. Python pip源,解决安装慢的问题
  2. Linux下直接读写物理地址内存
  3. SYN FLOOD学习理解
  4. codeforces 的 Codeforces Round #273 (Div. 2) --C Table Decorations
  5. Appium基础——one demo
  6. 模仿yui将css和js打包,加速网页速度
  7. Android5.0 CheckBox颜色修改
  8. html5--3.14 lable元素和label属性
  9. input处理函数
  10. Xamarin.Forms初始