oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • About
    • Terms of Use
    • Technical Specifications
    • Credits

cardtrick Batch , stdin/stdout

Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

statement.html

Problem Description

Aoki has a shuffled deck of cards which is a permutation of 1 to N. He wants to show off an impressive trick to his friends - dealing many cards in decreasing order!

However, Aoki only skilled enough to deal one of the top K cards of the deck. What is the longest sequence of cards of decreasing number he can deal?

Input

The first line of input will contain two integers, N and K.

The next line contain N integers, which respresent the deck. The first integer is the card that is on the top of the deck. Each number is between 1 to N inclusive, and no two numbers are the same.

Output

The output should contain one integer, the maximum number of cards Aoki can deal.

Limits

For all subtasks: 1 ≤ K ≤ N ≤ 500 000.

Subtask 1 (30%): K = 2.

Subtask 2 (70%): No additional constraints.

Subtask 3 (0%): Sample.

Sample Input

6 2
2 5 4 1 6 3

Sample Output

4

Explanation

He can deal the cards 5, 4, 2, 1 in this order. After this, there is no card smaller than 1, so it's impossible.

Tags

Data Structure

Subtasks and Limits

Subtask Score #TC Time Memory Scoring
130101s256MBMinimum
270201s256MBMinimum
3011s256MBMinimum

Judge Compile Command

g++-8 ans.cpp -o cardtrick -Wall -Wshadow -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512

Accepted Submissions

subIDUserTimeMax Time

Past Submissions

subIDUserTimeScore
mrJudge 09.05.20
Copyright © 2020 mrJudge. All rights reserved.