#P10240. [THUSC 2021] 搬东西
[THUSC 2021] 搬东西
Problem Description
There are items, numbered from to . The weight of item is denoted by , which is a positive integer.
There is only one available box, and its maximum capacity is a positive integer . 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 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 separated by spaces. The second line contains positive integers separated by spaces, which are the weights of the 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 items can be moved, and the index sequence is .
In the second batch, at most items can be moved. At this time there are different plans with the maximum number of items:
- Index sequence .
- Index sequence .
- Index sequence .
- Index sequence .
Choose the lexicographically largest one, .
In the third batch, at most item can be moved, and the index sequence is .
In the fourth batch, at most item can be moved, and the index sequence is .
[Subtasks]
| Subtask | Points | ||
|---|---|---|---|
All testdata satisfies:
- , ;
- For all item weights, , .
[Notes]
For two sequences and of the same length that are not identical, if the elements in the sequences can be compared, then the lexicographical order between and is defined as follows: scan from left to right to find the first position such that . If , then ; otherwise, if , then .
In this problem, and 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).
- Any organization or individual may use or redistribute the problems in this repository for free.
- 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.
- 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.
- The Department of Computer Science, Tsinghua University reserves all rights.
Translated by ChatGPT 5