1066D Boxes Packing

CF903C Boxes Packing 题解 所以这边长相等的两个盒子最终必定会在两个不同的盒子里,得出结论:答案为最多的重复次数。根据题目描述,每个盒子里不可能有两个边长相等的盒子,因为这样就不满足嵌套的要求了。来存,类似计数排序的过程统计重复次数,最后输出最大的即可。考虑边长值域可以使用。 阅读详情

题目:http://codeforces.com/contest/1066/problem/D

开始没看懂题意,后来看了note才明白。。。

Maksim has nn objects and mm boxes, each box has size exactly kk. Objects are numbered from 11 to nn in order from left to right, the size of the ii-th object is aiai.

Maksim wants to pack his objects into the boxes and he will pack objects by the following algorithm: he takes one of the empty boxes he has, goes from left to right through the objects, and if the ii-th object fits in the current box (the remaining size of the box is greater than or equal to aiai), he puts it in the box, and the remaining size of the box decreases by aiai. Otherwise he takes the new empty box and continues the process above. If he has no empty boxes and there is at least one object not in some box then Maksim cannot pack the chosen set of objects.

Maksim wants to know the maximum number of objects he can pack by the algorithm above. To reach this target, he will throw out the leftmost object from the set until the remaining set of objects can be packed in boxes he has. Your task is to say the maximum number of objects Maksim can pack in boxes he has.

Each time when Maksim tries to pack the objects into the boxes, he will make empty all the boxes he has before do it (and the relative order of the remaining set of objects will not change).

Input

The first line of the input contains three integers nn, mm, kk (1≤n,m≤2⋅1051≤n,m≤2⋅105, 1≤k≤1091≤k≤109) — the number of objects, the number of boxes and the size of each box.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤k1≤ai≤k), where aiai is the size of the ii-th object.

Output

Print the maximum number of objects Maksim can pack using the algorithm described in the problem statement.

Examples

input

Copy

5 2 6
5 2 1 4 2

output

Copy

4

input

Copy

5 1 4
4 2 3 4 1

output

Copy

1

input

Copy

5 3 3
1 2 3 1 1

output

Copy

5

解释一下,意思是他从第一个物品开始装,装不下了就换下一个物品,如果当前物品不能全部装入箱子,他会扔掉第一个物品,从第二个开始装。

理解了这个意思就简单多了,很明显装完之后最后一个物品一定被装进去了,那么我们可以从后往前找,看最多装几个,模拟一下就好了。

#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;

int a[N];
int main()
{
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    int cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
    }
    int ret = k;
    int i;
    for (i = n; i >= 1; i--)
    {
        if (a[i] <= ret)
        {
            ret -= a[i];
            cnt++;
        }
        else
        {
            m--;
            if (m == 0)
            {
                break;
            }
            ret = k - a[i];
            cnt++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

 

【信息科学与工程学】计算机科学与自动化——第六十六篇 算子篇 第一章 通用算子01 多模态数据(图形/图像/文本/语音)中推断人类内在状态、策略、动机和利益的算法算子知识库 编号领域算法/方法算子名称算子的数学方程式/表达复杂度 (示例)关联知识11量子场论正则量子化产生/湮灭算符对易关系: [â_p, â†_q] = δ⁽³⁾(p​ - q)应用于态空间,计算复杂度取决于截断福克空间,粒子数表象,二次量子化12统计力学蒙特卡洛模拟马尔可夫链转移算子T(s → s‘) :满足细致平衡条件 π(s)T(s→s’)=π(s‘)T(s’→s)收敛到平衡分布需 ~O(τ), τ为相关时间细致平衡,Metropolis-Hastings准则,重要性采样13电磁学边界元法单层势/双层势算子 阅读详情

相关推荐

小案例:利用图床自动化批量上传图片并获取图片链接

用python爬虫写了一个小脚本,用来自动上传图片到图床,然后返回链接,我们只需直接复制链接就可以。(需要安装Requests库) 因为不同图床需要提交的POST表单不一致,所以在这里我用ImgURL图床做示范,如果大家有需求,可自行修改代码。使用脚本的时候,我们只需把需要上传的图片和这个脚本放在同一个文件夹中,然后运行脚本,稍作等待,看到提示时就可以在脚本运行文件夹中发现一个名为“图片链接地址.txt”的文件,里面就是图片链接啦! 四、图片链接地址.txt(单张图片):...

采菊东篱下,Python满乾坤! 4427

Boxes Packing 思维+技巧

Maksim has nn objects and mm boxes, each box has size exactly kk. Objects are numbered from 11 to nn in order from left to right, the size of the ii-th object is aiai. Maksim wants to pack his object...

Sean 816

R语言实战:5分钟搞定NHANES数据库的加权分析与可视化(附完整代码)

本文提供了一份R语言实战指南,帮助研究者在5分钟内完成NHANES数据库的加权分析与可视化。通过详细的代码示例,涵盖数据获取、清洗、加权分析和可视化全流程,特别适合公共卫生和流行病学研究者快速掌握复杂抽样数据的处理方法。

www00的博客 265

CodeForces Round #515 Div.3 D. Boxes Packing

http://codeforces.com/contest/1066/problem/D Maksim hasnnobjects andmmboxes, each box has size exactlykk. Objects are numbered from11tonnin order from left to right, the size of theii-...

weixin_30849403的博客 165

从jieba分词到BERT-wwm——中文自然语言处理(NLP)基础分享系列(12)

今天是本系列的最后一期,完整代码呈现Huggingface transformers平台上微调BERT-wwm-ext的过程方法。

weixin_49518391的博客 3769

UFS逻辑单元管理

介绍UFS 逻辑单元管理和配置

m0_51720747的博客 1952

Boxes Packing

Boxes Packing Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai. Mishka can put a box i into another box j if the following conditions are met: i-th box is...

做一只熊猫不好吗? 437

Zabbix监控联想服务器XCC的SNMPv3配置实战

本文详细介绍了如何通过SNMPv3协议配置Zabbix监控联想服务器XCC的实战方法。文章从安全角度阐述了选择SNMPv3的必要性,并分步讲解了在XCC中启用SNMPv3、创建认证用户,以及在Zabbix中导入专用模板、创建主机并关联模板的完整流程,帮助运维人员实现对服务器硬件健康状态的自动化、安全监控。

weixin_29210727的博客 476

CF EDU 34 C 题 Boxes Packing 【思维】

传送门 // 题意: 给定n个盒子的大小, 是有当一个盒子要个小于另一个盒子时, 它才能被另一个盒子装下, 问最后还剩几个盒子. 被装进一个盒子的算剩一个.// 思路: 主要考虑这个样例1 1 1 2 3 3 4 答案应该是3, 实际上我们可以将n个盒子排序后统计好每一个大小的盒子的数量, 然后从大的开始往下面扫, 如果遇到一个盒子的数量大于了从上面下来的盒子数量, 那么答案应该加上多余出来的数

Anxdada -- 我等风来也等你 771

MLNX_OFED 5.4-3.7.5.0 驱动安装:银河麒麟V10SP2 ARM 内核升级后编译避坑 3 步

本文详细介绍了在银河麒麟V10SP2 ARM环境下安装MLNX_OFED 5.4-3.7.5.0驱动的完整流程,包括内核升级后的驱动兼容性挑战、编译环境准备、分步编译与安装流程以及性能优化与故障排查。特别针对国产化ARM服务器(如华为Atlas系列)提供了实用的解决方案和常见问题处理建议,帮助用户顺利完成mlnx网卡驱动的安装与配置。

weixin_29184075的博客 407

Unity特效序列帧输出全攻略:Recorder+Timeline保姆级教程(解决透明通道问题)

本文提供Unity特效序列帧输出的完整解决方案,重点讲解如何结合Recorder与Timeline工具,实现带透明通道的PNG序列帧高效输出。通过保姆级教程,详细解析摄像机隔离、层级设置、参数配置等关键步骤,并深度解决透明通道丢失等常见问题,帮助特效师和动画师打通引擎创作与后期合成的工作流。

tensorflowjs6的博客 433

CF1066D Boxes Packing 题解

题意简化: 有NNN个数,第i个数为aia_{i}ai​,你需要选出至多MMM个子序列,使得每一个子序列的和都<=k,并且这些子序列在原序列里面必须连续且靠右。问能选出多少个数。 1.暴力 我们可以枚举一个数iii(1<=iii<=NNN),表示前i个数不选,选第i+1i+1i+1到第NNN个数,再利用如下的代码进行判断。如果返回true,那么输出n−in-in−i。时间复杂度O...

Plozia 的小窝 409

【系统移植】 移植主线U-Boot(v2024.01-rc3)到RK3399

[系统移植] 移植主线U-Boot(v2024.01-rc3)到RK3399

Systemcall名屋 1012

CF1066D Boxes Packing

传送门 这题为什么要用二分呢?/huaji 首先可以\(O(n)\)预处理出从某个物品\(i\)开始放,只放一个盒子,能放的最后物品的位置\(j\),只要用两个指针维护左右端点,每次移动一下左端点同时尽量把右端点右移救星了 然后我们要放的所有物品是原来的一个后缀,所以要从后往前放,但是直接贪心放是错的.考虑构建一棵树,根据前面对每个\(i\)预处理出的\(j\),连\((j+1,i)\)的单向边,...

weixin_30951231的博客 197

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

Codeforces 1066D Boxes Packing (模拟+题意。。。)

题目链接:http://codeforces.com/problemset/problem/1066/D #include&lt;bits/stdc++.h&gt; using namespace std; #define debug puts("YES"); #define rep(x,y,z) for(int (x)=(y);(x)&lt;(z);(x)++) #define ll lo...

满月照亮的路 367

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

codeforces1066D. Boxes Packing(二分)

D. Boxes Packing time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Maksim has nn objects and mm boxes, each box has size exactly kk....

Amove 505

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

CodeForces - 1066D Boxes Packing 没做出来 题意 思维

D. Boxes Packing time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Maksim has nn objects and mm boxes, each box has size exactly kk....

pxlsdz的博客 805

codeforces 1066 D. Boxes Packing(二分||模拟)

D. Boxes Packing time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Maksim has nn objects and mm boxes, each box has size exactly kk. Objects are ...

- 回忆゛ 509

CF1066D Boxes Packing(二分答案)

题意描述: 你有$n$个物品,每个物品大小为$a_i$,$m$个盒子,每个盒子的容积为$k$。$Maksim$先生想把物品装入盒子中。对于每个物品,如果能被放入当前的盒子中,则放入当前盒子,否则换一个新的盒子放入。为了放入尽可能多数量的物品,$Maksim$先生会从左开始扔掉一部分物品。现在,$Maksim$先生想知道,他最多能放入盒子多少物品 输入输出格式: 输入格式: 第一行,三个整数...

weixin_30641999的博客 227

Codeforces Round #515 (Div. 3) D. Boxes Packing

题解 题目大意 n个物品m个篮子每个篮子容量为k 每个物品重量为a[i] 问能装多少物品 这个人是强迫症 如果没把所有物品装完则把第一个物品丢掉 直接倒着装就行。。模拟一下 或者二分答案 主要是看懂题意 AC代码 #include &amp;lt;stdio.h&amp;gt; #include &amp;lt;bits/stdc++.h&amp;gt; using namespace std; typedef long lon...

CaprYang的博客 917

D. Boxes Packing(思维-反向思考)

https://codeforces.com/problemset/problem/1066/D 题目描述 Maksim hasnnobjects andmmboxes, each box has size exactlykk. Objects are numbered from11tonnin order from left to right, the size of theii-th object isa_iai​. Maksim wants to pack hi...

代码笔记本 414

D. Boxes Packing

链接 [http://codeforces.com/contest/1066/problem/D] 题意 题目大意 n个物品m个篮子每个篮子容量为k 每个物品重量为a[i] 问能装多少物品 这个人是强迫症 如果没把所有物品装完则把第一个物品 也就是最左边的那个直接从右边枚举就行了 代码 #include<bits/stdc++.h> using namespace std; #defi...

weixin_30561177的博客 194

903C Boxes Packing

C. Boxes Packing time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Mishka has got n empty boxes. For every i (

memory_qianxiao的博客 1076

codeforces C. Boxes Packing

C. Boxes Packingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side...

q1248807225的博客 518

H - Boxes Packing

Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai. Mishka can put a box i into another box j if the following conditions are met: i-th box is not put in

Abandoninged的博客 924
上一篇: 1066C Books Queries
下一篇: cf1066E Binary Numbers AND Sum
「已注销」
博客等级 码龄9年 6粉丝 32原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值