#P10240. [THUSC 2021] 搬东西

[THUSC 2021] 搬东西

Problem Description

There are nn items, numbered from 11 to nn. The weight of item ii is denoted by aia_i, which is a positive integer.

There is only one available box, and its maximum capacity is a positive integer mm. The items are moved in batches. In each batch, some of the remaining items are moved away, until all items have been moved. The items moved in each batch form a subset of the items remaining at that time, chosen by the following strategy:

Choose a plan such that the total weight does not exceed mm and the number of included items is as large as possible. If there are multiple plans with the maximum number of items, then sort the chosen item indices in increasing order into a sequence, and choose the plan whose sequence is lexicographically largest.

Compute how many batches will be needed under this strategy.

Input Format

The input has two lines. The first line contains two positive integers n,mn, m separated by spaces. The second line contains nn positive integers separated by spaces, which are the weights aia_i of the nn items in order.

Output Format

Output one positive integer, representing the number of batches required to finish moving.

11 10
3 1 3 8 4 3 2 1 2 1 1

4

见附件中的 2.in。
见附件中的 2.ans。
见附件中的 3.in。
见附件中的 3.ans。

Hint

[Sample Explanation #1]

In the first batch, at most 66 items can be moved, and the index sequence is 6,7,8,9,10,116, 7, 8, 9, 10, 11.

In the second batch, at most 33 items can be moved. At this time there are 44 different plans with the maximum number of items:

  • Index sequence 1,2,31, 2, 3.
  • Index sequence 1,2,51, 2, 5.
  • Index sequence 1,3,51, 3, 5.
  • Index sequence 2,3,52, 3, 5.

Choose the lexicographically largest one, 2,3,52, 3, 5.

In the third batch, at most 11 item can be moved, and the index sequence is 44.

In the fourth batch, at most 11 item can be moved, and the index sequence is 11.

[Subtasks]

Subtask Points nn mm
11 55 n20n \leq 20 m100m \leq 100
22 2525 n500n \leq 500 m109m \leq 10^9
33 2020 n3000n \leq 3000
44 1010 n50000n \leq 50000 m10m \leq 10
55 4040 m109m \leq 10^9

All testdata satisfies:

  • 1n500001 \leq n \leq 50000, 1m1091 \leq m \leq 10^9;
  • For all item weights, 1aim1 \leq a_i \leq m, i=1ni=1 \dots n.

[Notes]

For two sequences aa and bb of the same length that are not identical, if the elements in the sequences can be compared, then the lexicographical order between aa and bb is defined as follows: scan from left to right to find the first position ii such that aibia_i \neq b_i. If ai<bia_i < b_i, then a<ba<b; otherwise, if ai>bia_i>b_i, then a>ba>b.

In this problem, aa and bb are the sequences of item indices involved in two moving plans, and comparing elements means comparing the indices as integers.

Problem License

From the Tsinghua University 2021 National Outstanding High School Students Informatics Experience Camp (THUSC 2021).

In the following, “this repository” refers to the official THUSC 2021 repository (https://gitlink.org.cn/thusaa/thusc2021).

  1. Any organization or individual may use or redistribute the problems in this repository for free.
  2. When using the problems in this repository, any organization or individual should do so free of charge and publicly. It is strictly forbidden to use these problems for profit or to add special access restrictions to these problems.
  3. If possible, please provide methods to obtain resources such as testdata, reference solutions, and editorials when using the problems in this repository; otherwise, please attach the link to this repository.
  4. The Department of Computer Science, Tsinghua University reserves all rights.

Translated by ChatGPT 5