CF1119B.Alyona and a Narrow Fridge

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alyona has recently bought a miniature fridge that can be represented as a matrix with hh rows and 22 columns. Initially there is only one shelf at the bottom of the fridge, but Alyona can install arbitrary number of shelves inside the fridge between any two rows. A shelf is two cells wide, does not occupy any space but separates the inside of the fridge to the lower and upper part.

An example of a fridge with h=7h = 7 and two shelves. The shelves are shown in black. The picture corresponds to the first example.

Alyona has nn bottles of milk that she wants to put in the fridge. The ii-th bottle is aia_i cells tall and 11 cell wide. She can put a bottle on some shelf if the corresponding space above the shelf is at least as tall as the bottle. She can not put a bottle on top of another bottle (if there is no shelf between them). Two bottles can not share a cell.

Alyona is interested in the largest integer kk such that she can put bottles 11, 22, ..., kk in the fridge at the same time. Find this largest kk.

阿廖娜最近购买了一台微型冰箱,该冰箱可表示为一个 hh 行 22 列的矩阵。冰箱最底部初始仅有一层搁板,但阿廖娜可以在任意两行之间安装任意数量的搁板。每层搁板宽度为 22 个单元格,本身不占用空间,仅将冰箱内部划分为上、下两个部分。


一个 h=7h = 7 且装有两层搁板的冰箱示例。搁板以黑色显示。该图对应第一个样例。

阿廖娜有 nn 瓶牛奶,她希望将这些瓶子放入冰箱中。第 ii 瓶牛奶高度为 aia_i 个单元格,宽度为 11 个单元格。她可以将某瓶牛奶放在某一层搁板上,当且仅当该搁板上方的空间高度至少等于该瓶牛奶的高度。她不能将一瓶牛奶直接叠放在另一瓶牛奶之上(即若两瓶牛奶之间没有搁板,则不允许叠放)。任意两个瓶子不能占据同一个单元格。

阿廖娜关心的是最大的整数 kk,使得她能同时将第 1,2,…,k1, 2, \dots, k 瓶牛奶全部放入冰箱中。请找出这个最大的 kk。

输入格式

The first line contains two integers nn and hh (1≤n≤1031 \le n \le 10^3, 1≤h≤1091 \le h \le 10^9) — the number of bottles and the height of the fridge.

The second line contains nn integers a1a_1, a2a_2, ..., ana_n (1≤ai≤h1 \le a_i \le h) — the heights of the bottles.

第一行包含两个整数 nn 和 hh(1≤n≤1031 \le n \le 10^3,1≤h≤1091 \le h \le 10^9)——分别为瓶子的数量和冰箱的高度。

第二行包含 nn 个整数 a1a_1、a2a_2、...、ana_n(1≤ai≤h1 \le a_i \le h)——分别为各瓶子的高度。

输出格式

Print the single integer kk — the maximum integer such that Alyona can put the bottles 11, 22, ..., kk in the fridge at the same time. If Alyona can put all bottles in the fridge, print nn. It is easy to see that Alyona can always put at least one bottle in the fridge.

输出单个整数 kk —— 即 Alyona 能够同时将编号为 1,2,…,k1, 2, \dots, k 的瓶子放入冰箱的最大整数。如果 Alyona 能将所有瓶子都放入冰箱,则输出 nn。显然,Alyona 总是至少能将一个瓶子放入冰箱。

输入输出样例

  • 输入#1

    5 7
    2 3 5 4 1

    输出#1

    3
  • 输入#2

    10 10
    9 1 1 1 1 1 1 1 1 1

    输出#2

    4
  • 输入#3

    5 10
    3 1 4 2 4

    输出#3

    5

说明/提示

One of optimal locations in the first example is shown on the picture in the statement.

One of optimal locations in the second example is shown on the picture below.

One of optimal locations in the third example is shown on the picture below.

第一个样例中的一个最优位置如题面图片所示。

第二个样例中的一个最优位置如下图所示。

第三个样例中的一个最优位置如下图所示。

输入解题思路,AI测评打分。不知道怎么写?

首页