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;
}



DeepSeek研发的精算大模型「精卫」已实现98%精算任务覆盖,中国人寿采用后年节约3.2亿元技术采购成本,形成关键技术替代效应 根据现有资料,精算领域关键技术替代效应的行业标准定义尚未明确具体提及。然而,可以从相关文献中提取一些关键概念和方法来推导出可能的定义。​替代效应的基本定义​:替代效应是指一种商品价格变动引起另一种商品的相对价格变动,从而导致消费者在维持原有效用水平不变的条件下对商品需求量做出的调整。​技术替代效应​:在精算领域,技术替代效应可以理解为新技术或新方法对现有技术或方法的替代,从而影响精算模型、数据处理和决策过程。例如,机器学习在精算中的应用日益增长,改变了精算师的工作方式和模型构建方法。​。 阅读详情

相关推荐

手把手教你配置UEFI Secure Boot:从密钥生成到系统验证(附避坑指南)

本文详细介绍了如何配置UEFI Secure Boot,从密钥生成到系统验证的全过程,包括PK、KEK等关键密钥的生成方法,以及常见问题的解决方案。通过实战案例和避坑指南,帮助用户有效提升系统启动安全性,防止恶意软件植入。

weixin_30776273的博客 349

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的博客 333

ROS四旋翼无人机快速上手指南(4):阿木实验室PX4功能包飞行控制分析与讲解(重点章节)

成就更好的自己 这一章详细讲解一下阿木实验室(AMOV)的开源项目px4_command功能包,此功能包通过mavlink协议直接控制烧录px4固件的自驾仪,还融合了来自各个传感器的位姿,距离等信息,此外,功能包提供的接口向上对接应用层算法级的程序例如SLAM,kfc目标检测引导,路径规划等算法,因此,在整个无人机控制中起到了承上启下至关重要的作用。 用到的文件及工具包链接如下: AMOV实验室源码如下: https://gitee.com/theroadofengineers/px4_comman

The Road of Engineer 6177

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

腾讯Octop:Windows本地AI助手一键安装实战指南

本地AI助手是面向普通用户在个人设备上运行大语言模型的轻量级解决方案,其核心原理在于封装模型加载、推理调度与Web交互等底层复杂性,通过预编译运行时、自适应硬件加速和图形化配置降低使用门槛。技术价值体现在免环境依赖、离线可用、开箱即用,显著提升非开发者在专利撰写、文案生成、技术文档处理等办公场景中的生产力。本文聚焦Windows平台下的腾讯Octop工具,结合qwen2-7b-instruct、phi-3-mini等主流GGUF量化模型,详解安装适配、API集成与专利辅助工作流,覆盖从零部署到工程落地的完整

weixin_29055137的博客 320

基因家族快速鉴定指南:Windows平台下的HMMER实战解析

本文详细解析了在Windows平台下使用HMMER工具进行基因家族快速鉴定的完整实战流程。通过手把手指导,从软件获取、数据准备到模型构建与序列搜索,帮助生物信息学新手无需Linux环境,即可高效完成bZIP转录因子等家族的鉴定工作,大幅降低分析门槛。

weixin_29255731的博客 465

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

LFM线性调频信号的MATLAB仿真

线性调频(LFM)是一种不需要伪随机编码序列的扩展频谱调制技术。由于线性调频信号占用的频带宽度远大于信息带宽,所以也可以获得很大的系统处理增益。线性调频信号又称鸟声(Chirp)信号,因为其频谱带宽落于可听范围,则听若鸟声,所以又称Chirp扩展频谱(CSS)技术。LFM技术在雷达、声纳技术中有广泛应用,如在雷达定位技术中,它可在增大射频脉冲宽度、提高平均发射功率、加大通信距离同时又保持足够的信号频谱宽度,不降低雷达的距离分辨率。线性调频(LFM)是一种不需要伪随机编码序列的扩展频谱调制技术。

平时工作较为繁忙,私信消息一般晚上回复,谢谢大家~~ 908

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

(8-5)图像特征提取:基于LoG、DoG 和DoH 的斑点检测器

然后,根据给定的参数(标准差、尺度因子),通过调用cv2.GaussianBlur函数创建了两个不同尺度的高斯滤波器,并对图像进行滤波操作。然后,通过遍历DoG滤波器的每个像素,检测局部极值点,并将其添加到关键点列表中。然后,通过遍历DoH滤波器的每个像素,检测局部极值点,并将其添加到关键点列表中。接下来,通过遍历滤波器的每个像素,检测局部极值点,并将其添加到关键点列表中。DoH是一种基于Hessian矩阵的特征检测方法,通过计算Hessian矩阵的行列式来检测图像中的斑点。:实现DoH斑点检测器。

码农三叔 1609

华为HCIP的学习大纲和计划

HCIP(华为认证 ICT 高级工程师)核心围绕华为 ICT 技术体系,不同方向(如路由交换、云计算、安全等)课程目录不同,以下是最热门的。

迷逝 589

【题解】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 1560

基于 高斯过程回归(Gaussian Process Regression, GPR) 的 时间序列区间预测 的 MATLAB 示例代码

基于 高斯过程回归(Gaussian Process Regression, GPR) 的 时间序列区间预测 的 MATLAB 示例代码

算法如诗的博客 158

CodeForces - 366 C.Dima and Salad

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

snayf的博客 370

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

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

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

CodeForces 366C Dima and Salad

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

temp06的博客 317

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

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

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 560

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的博客 679

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 317

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的博客 462

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 164

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

[codeforces366C]Dima and Salad

time limit per test : 1 second memory limit per test : 256 megabytes 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 ...

dxyinme-Zz 352
上一篇: 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、付费专栏及课程。

余额充值