Programming contests

ACM ICPC programozó csapatverseny, házi forduló, 2018. október 31.

October 31, 2018 10:10 AM – October 31, 2018 3:10 PM

Trainsorting

Erin is an engineer. She drives trains. She also arranges the cars within each train. She prefers to put the cars in decreasing order of weight, with the heaviest car at the front of the train.

Unfortunately, sorting train cars is not easy. One cannot simply pick up a car and place it somewhere else. It is impractical to insert a car within an existing train. A car may only be added to the beginning and end of the train.

Cars arrive at the train station in a predetermined order. When each car arrives, Erin can add it to the beginning or end of her train or refuse to add it at all. The resulting train should be as long as possible, but the cars within it must be ordered by weight.

Given the weights of the cars in the order in which they arrive, what is the longest train that Erin can make?

Input Specification

The first line contains an integer 0 ≤ n ≤ 2000, the number of cars. Each of the following n lines contains a nonnegative integer giving the weight of a car. No two cars have the same weight.

Output Specification

Output a single integer giving the number of cars in the longest train that can be made with the given restrictions.

Sample Input

  1. 3
  2. 1
  3. 2
  4. 3
download as text file

Output for Sample Input

  1. 3
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019