#P3845. Missed Matches Due to a Date
Missed Matches Due to a Date
Missed Matches Due to a Date
H has obtained all the game scores recorded by Little H, but note that the scores are not in chronological order. H wants to determine the minimum number of matches he must have missed this weekend because of his date. It is assumed that if H attended a match, then the scores of the matches he attended (in the order they occurred) would form a strictly increasing sequence.
In other words, your task is to find the length of the Longest Increasing Subsequence (LIS) of the given scores, and then output the difference between the total number of matches and the length of this subsequence. Formally, if there are n matches and the LIS has length l, then the answer is n - l.
The mathematical formulation is: \( \text{Answer} = n - |LIS| \).
inputFormat
The input consists of two lines:
- The first line contains a single integer n (number of matches).
- The second line contains n space-separated integers representing the scores of the matches.
outputFormat
Output a single integer: the minimum number of matches that H must have missed on the weekend.
sample
5
3 1 2 4 6
1