codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

879B.md (1519B)


      1 Source: https://codeforces.com/problemset/problem/879/B
      2 
      3 B. Table Tennis
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 *n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
     22 
     23 For each of the participants, you know the power to play table tennis, and for all players these values are different. In a game the player with greater power always wins. Determine who will be the winner.
     24 
     25 Input
     26 
     27 The first line contains two integers: *n* and *k* (2 ≤ *n* ≤ 500, 2 ≤ *k* ≤ 1012) — the number of people and the number of wins.
     28 
     29 The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ *n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all *a**i* are distinct.
     30 
     31 Output
     32 
     33 Output a single integer — power of the winner.
     34 
     35 Examples
     36 
     37 Input
     38 
     39 ```
     40 2 2  
     41 1 2
     42 ```
     43 
     44 Output
     45 
     46 ```
     47 2
     48 ```
     49 
     50 Input
     51 
     52 ```
     53 4 2  
     54 3 1 2 4
     55 ```
     56 
     57 Output
     58 
     59 ```
     60 3
     61 ```
     62 
     63 Input
     64 
     65 ```
     66 6 2  
     67 6 5 3 1 2 4
     68 ```
     69 
     70 Output
     71 
     72 ```
     73 6
     74 ```
     75 
     76 Input
     77 
     78 ```
     79 2 10000000000  
     80 2 1
     81 ```
     82 
     83 Output
     84 
     85 ```
     86 2
     87 ```
     88 
     89 Note
     90 
     91 Games in the second sample:
     92 
     93 3 plays with 1. 3 wins. 1 goes to the end of the line.
     94 
     95 3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner.