#1960. [Baltic2010] Bins

[Baltic2010] Bins

题目描述

There is a large number of empty bins in a factory depot. The bins are arranged in a single row. The manager of the depot wants to put some bins into other bins to make some free space in the left end of the depot. Bins can be moved by a robot, which can take a bin, carry it to the right, and put it into a larger bin. This three-operation sequence is the only allowed way to move bins.

Because of safety regulations, any bin can contain at most one other bin, which must be empty. The manager also wants to keep the double bins in the left end of the resulting row, to make it easier to keep track of them.

You are to write a program that computes the largest possible kk such that the kk leftmost bins can be put into the immediately following kk bins in some order.

输入格式

The first line of the text file bins.in contains two integers, separated by a space: mm, the size of the largest bin, and nn, the number of bins. The second line contains nn integers ai(1aim)a_i(1 \le a_i \le m), separated by spaces: the sizes of the bins, listed from left to right.

输出格式

The first and only line of the text file bins.out should contain a single integer, the largest number kk such that the robot can put the kk leftmost bins into the next kk bins.

5 10
2 2 1 4 3 2 5 4 2 3
4

数据规模与约定

For all the test cases, 1n2×1041 \le n \le 2 \times 10^4, 1m1031 \le m \le 10^3.