#QHD0000075. Xếp chồng các hộp (Boxes)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Xếp chồng các hộp (Boxes)
Boxes
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
There are equal-sized boxes, numbered through . Box has weight and load capacity . The total weight of every box above box , excluding its own weight, must not exceed .
Select any subset of boxes and arrange them into one vertical stack, with at most one box directly above any box. The serial-number rule forbids placing a lower-numbered box on a higher-numbered box. Consequently, indices must be strictly increasing from the bottom to the top of the stack. For example, using boxes requires the bottom-to-top order .
Each selected box must support the total weight above it, not just the adjacent box. Find the maximum possible number of boxes in a valid stack. The selected indices do not need to be printed.
Input
The first line contains . Each of the next lines contains the integers for box .
Output
Print the maximum number of boxes that can be placed in one valid stack.
Subtasks
-
Subtask 1 (20 points): ; ; indices increase strictly from bottom to top.
-
Subtask 2 (30 points): ; ; indices increase strictly from bottom to top.
-
Subtask 3 (50 points): ; ; indices increase strictly from bottom to top.
Examples
Example 1
Input
5
19 15
7 13
5 7
6 8
1 2
Output
4
Explanation
Place boxes from bottom to top. The loads above them are , , , and . Four boxes are valid, whereas five are not.
Example 2
Input
3
1 0
1 0
1 0
Output
1
Explanation
Every box has zero load capacity while each weighs one unit, so no box can support another; the answer is one.