CodeForces - 366C Dima and Salad

CodeForces - 366C(2020.4.19训练A题) Problem Dima, Inna and Seryozha have gathered in a room. That’s right, someone’s got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have ... 阅读详情

C. Dima and Salad
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something.

Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words,  , where aj is the taste of the j-th chosen fruit and bj is its calories.

Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem — now the happiness of a young couple is in your hands!

Inna loves Dima very much so she wants to make the salad from at least one fruit.

Input

The first line of the input contains two integers n, k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10). The second line of the input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 100) — the fruits' calories. Fruit number i has taste ai and calories bi.

Output

If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer — the maximum possible sum of the taste values of the chosen fruits.

Examples
input
3 2
10 8 1
2 7 1
output
18
input
5 3
4 4 4 4 4
2 2 2 2 2
output
-1
Note

In the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition  fulfills, that's exactly what Inna wants.

In the second test sample we cannot choose the fruits so as to follow Inna's principle.


把a-b*k视为重量,a视为价值,背包,因为a-b*k有负数情况,所以要考虑负数容量的情况


把a-b*k视为重量,是因为这样就可以叠加,当a=b*k时,也就是重量为0的状态,    初始没有物品时,重量也为零,所以dp数组初始化要讲重量为0(dp【0】)赋为零,而其余状态刚开始并不存在,所以都赋为负无穷


#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f;
int dp[2][10050];
int main()
{
	int x,j,ans,n,k,i,a[200],b[200];
	for(i=0;i<2;i++)
	for(j=1;j<10050;j++)
	dp[i][j]=-1*inf;
	dp[0][0]=dp[1][0]=0;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	for(i=0;i<n;i++)
	scanf("%d",&b[i]),b[i]=a[i]-b[i]*k;
	for(i=0;i<n;i++)
	{
		if(b[i]>0)
		{
			for(j=10000;j>=b[i];j--)
			{
				dp[0][j]=max(dp[0][j-b[i]]+a[i],dp[0][j]);
			}
		}
		else
		{
			x=-1*b[i];
			for(j=10000;j>=x;j--)
			{
				dp[1][j]=max(dp[1][j-x]+a[i],dp[1][j]);
			}
		}
	}
	ans=0;
	for(i=0;i<=10000;i++)
	{
		ans=max(ans,dp[0][i]+dp[1][i]);
	}
	if(ans==0)
	printf("-1\n");
	else
	printf("%d\n",ans);
	return 0;
}



10分钟上手YOLOv11:最强姿态估计模型来了,代码开源,效果炸裂! 【10分钟玩转YOLOv11实时姿态估计】🚀 YOLOv11作为YOLO家族最新成员,在速度、精度和易用性上全面升级,尤其适用于姿态估计等复杂视觉任务。本文带您快速掌握: 1️⃣ 核心概念:姿态估计即识别人体17个关键点(如关节部位)并连接成数字骨架,是智能健身、体感游戏等应用的基础。 2️⃣ 技术优势: 超轻量级(最小仅2.9M参数) 极速推理(GPU仅1.7ms) 高精度(COCO mAP@50-95达50%) 3️⃣ 三步实操: ① 安装:pip install ultralytics ② 准备人物 阅读详情

相关推荐

深度学习模型轻量化方法之【量化】

量化虽然有着硬件友好和功效提升的特点,但它也引入了模型性能的折衷。因此,设计有效的量化策略需要在模型大小、性能以及运算速度之间做出平衡。随着深度学习算法和硬件加速技术的快速发展,量化方法在使深度网络轻量化和提高部署效率方面持续发挥着重要作用。

m0_73916791的博客 2847

C - Dima and Salad CodeForces - 366C

Dima, Inna and Seryozha have gathered in a room. That’s right, someone’s got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have n fru...

qq_43690454的博客 332

Lumerical官方案例、FDTD时域有限差分法仿真学习(三)——环形谐振器(Ring resonator)之第一部分

环形谐振器教程的第 1 部分使用 MODE 来设计和仿真环形谐振器。 自由光谱范围 (FSR) 和品质因数 (Q 因数) 是这种面向片上通信应用的基于绝缘体上硅 (SOI) 波导设计的关键性能指标。

weixin_45719141的博客 3万+

Codeforces 366C Dima and Salad 【dp】

题目链接:Codeforces 366C Dima and Salad C. Dima and Salad time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Dima, Inna and Seryozha have gather

世界很大 1151

利用makehumancommunity导入人体模型到COMSOL里(需要solidwork)

#makehumancommunity #solidwork #COMSOL

qq_41227634的博客 2158

从零开始:如何用Python手绘波特图并分析电路稳定性

本文详细介绍了如何使用Python绘制波特图并分析电路稳定性,涵盖从基础理论到实际应用的完整流程。通过NumPy和Matplotlib实现频域分析,包括RC低通滤波器和RLC带通滤波器的案例,以及相位裕度计算等高级技巧,为电子工程师提供了一套高效的电路分析解决方案。

hhh00的博客 371

Codeforces Round #214 (Div. 2) C. Dima and Salad 背包

C. Dima and Salad Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook so...

weixin_30521649的博客 176

按照autoware.universe官方从零搭建自己的自动导航小车(三)(续)

本文介绍了在Autoware框架下完善自定义传感器套件描述包的详细过程。主要内容包括:1)创建传感器描述包tinyplc_sensor_kit_description,包含YAML标定文件和URDF模型;2)配置传感器与车辆基座的相对位姿,实现sensor_kit.xacro和sensors.xacro宏文件;3)更新sensor_kit.launch.xml文件以集成激光雷达和GNSS/IMU驱动。通过xacro验证URDF模型正确性后,下一步计划接入Helios16激光雷达数据并在Rviz2中验证点云显

qq_45335326的博客 1272

【codeforce C】 Dima and Salad 01背包

Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have n frui...

胖亚亚的小酒馆 522

uniapp [移动端H5网页] - 强力解决弹起软键盘后页面被挤压变形或页面整体上移问题,点击input输入框键盘弹出底部被上推往上顶遮挡及各种问题(兼容安卓苹果ios手机,微信公众号网页也适用)

uni-app,h5网页,input输入框组件,uniapp h5软键盘弹出,uni-app 输入框,键盘弹起时页面整体上移问题,uni,H5页面,解决软键盘弹起页面被挤压、被往顶的问题,解决uni-app 输入框,键盘弹起时页面整体上移问题,uniapp调用手机系统软键盘,页面窗口被顶起,布局定位失效,解决uniapp软键盘弹起导致页面fixed定位元素被顶上去,输入法软键盘弹起,窗口顶起,变形解决办法,UniApp中input组件在IOS设备上弹出软键盘时页面整体上移问题的解决方案,以及input组件聚

🏆 前端领域优质创作者 1万+

李宏毅2025《机器学习》第一讲-生成式AI:技术突破和未来发展

本文基于台湾大学李宏毅教授的“一堂课搞懂生成式人工智慧的技术突破与未来发展”课程内容,系统性地梳理了生成式AI的核心概念、技术原理、发展演进以及未来趋势。文章从AI的“行为”入手,通过生动的实例展示了其强大的生成与推理能力;进而深入剖析其底层运作机制,阐释了“万物皆为令牌(Token)”、自回归生成、Transformer架构等核心原理;接着,文章追溯了通用AI模型从“专才”到“通才”的演进历程;最后,探讨了如何通过微调(Fine-tuning)、模型编辑(Model Editing)等技术赋予AI新的能力

木鱼时刻的专栏 2295

【题解】Dima and Salad CodeForces - 366C⭐⭐⭐ 【01背包 思维】

Dima and Salad CodeForces - 366C 有n个水果, 每个水果都有两个属性值ai表示美味程度, bi表示能量值, 现在要求选出一个或多个水果, 使得选出的水果的ai和与bi和的比例是k 问在这种清形可能出现的情况下ai的和最多是多少, 如果这样的情形不存在输出 -1 Input 第一行包含两个整数n, k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10). 第二行为 ...

Suprit's blog 1555

华为OD新系统机试真题 - 获取大写字母瓷砖拼出独特图案数量

华为OD机试新系统真题【获取大写字母瓷砖拼出独特图案数量】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD新系统四月二十九号机试真题【获取大写字母瓷砖拼出独特图案数量】

qq_45776114的博客 1218

CodeForces - 366C Dima and Salad(dp)

C. Dima and Salad 题意:给n个水果和k值,每个水果有a和b两种属性。选一些水果使suma比sumb为k。求max suma; 题解:求出每个水果的x = a-b*k。当选中的水果的x值之和为0时,就是比值为k的条件,因此题目就转换为01满背包问题,dp【0】就是答案。a就是每个水果的价值。 方法1:分别dp x值为正数和负数时,dp[j+x[i]] = max(dp[...

ayyyyy_zc的博客 385

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

CodeForces - 366 C.Dima and Salad

                                                                             C. Dima and Salad                                                                           time limit per test1 second  ...

snayf的博客 370

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

CodeForces 366C Dima and Salad

C. Dima and Salad time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dima, Inna and Seryozha have gathered in a

码代码的猿猿 1818

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

CodeForces 366C Dima and Salad

题解:一开始想到用类似背包DP的思路去DP,然而效率上无法接受。发现这一题虽然有两个空间限制,但是并不需要求最大值,需要维护的是能否凑出来。所以考虑放弃暴力枚举每一个空间,使用vector来存储每个可能的a[i]的和有哪些可能的b[i]的和,就能减少大量无谓的判断,大大优化效率,通过这道题。 代码如下: #include&lt;bits/stdc++.h&gt; using namespac...

temp06的博客 317

Codeforces 366C. Dima and Salad (DP)

题目: http://codeforces.com/problemset/problem/366/C 题意: n个物品,每个物品两个属性(ai,bi); 给定一个数k,求是否能选择m个物品使得满足: 输出满足条件的最大的 ∑aj 分析: ∑aj / ∑bj = k ∑aj - k*∑bj =0 将每个物品的属性改为 cj = aj - k*bj; 那么条件变为选择一些物品使得∑cj=0 变成一个...

OI -> ACM -> AI 559

Codeforces 366C Dima and Salad:背包dp

题目链接:http://codeforces.com/problemset/problem/366/C 题意:   有n个物品,每个物品有两个属性a[i]和b[i]。   给定k,让你选出一些物品,使得 ∑ a[i] / ∑ b[i] = k。   问你选出物品的 ∑ a[i]最大是多少。 题解:   将原式变形:     ∑ a[i] - k * ∑ b[i] = ...

a1392136的博客 208

Codeforces 366C Dima and Salad 【01背包准换 妙 负数背包的实现】好题

题目链接:Codeforces 366C Dima and Salad  C. Dima and Salad  time limit per test1 second  memory limit per test256 megabytes  inputstandard input  outputstandard output  Dima, Inna and Seryozha have gather...

pxlsdz的博客 677

Codeforces 366C - Dima and Salad(DP)

C. Dima and Salad time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Dima, Inna and Seryozha have gathered in a room. That’s right, someone’s

Snakeflute的博客 658

Codeforces 366C Dima and Salad(dp)

题目链接:http://codeforces.com/contest/366/problem/C #include #include #include #include #include #include #include #include #include #include #include #include #include #include using names

llmxby 316

codeforces 366C - Dima and Salad (dp)

C. Dima and Salad time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Dima, Inna and Seryozha have gathered in a room. That's right, s...

LSD20164388的博客 461

CodeForces - 366C Dima and Salad

Dima, Inna and Seryozha have gathered in a room. That’s right, someone’s got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have n fruits...

slass-mot-odet 163

Codeforces 366C Dima and Salad 背包DP

题目大意: 就是现在又n个水果, 每个水果都有两个属性值ai表示美味程度, bi表示能量值, 现在要求选出多个或一个水果, 使得选出的水果的ai和与bi和之比是k 问在这种清形可能出现的情况下ai的和最多是多少, 如果这样的情形不存在输出 -1 (1 大致思路: 首先我们最终要满足sigma(ai)/sigma(bi) = k所以对于每一个水果记ci = ai - k*bi那么

Gatevin的专栏 930

CodeForces - 366C Dima and Salad (DP&01背包)

CodeForces - 366C Dima and Salad Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Dima, Inna and Seryozha have ga

yanghui07216的博客 847
上一篇: B. The Meeting Place Cannot Be Changed
下一篇: UVA - 674 Coin Change 多重背包or母函数
jerans
博客等级 码龄10年 54粉丝 255原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值