No.2777 Wild Flush
タグ : / 解いたユーザー数 130
作問者 :
amentorimaru
Story
Yu-san has invited a friend over to his now-clean room to play a game called "Yu-san Poker".
This game called "Yu-san Poker" is one where players make hands and compete on their strength like in ordinary poker, but it has a special system in which you choose some cards from your hand and play them.
In addition, the playing cards used in "Yu-san Poker" include jokers, which can be used in place of any card.
However, Yu-san is not good at memorizing hands, so all he can think about is playing a "Flush", which is made by matching suits (the marks on playing cards).
Yu-san is fired up, saying, "Flushes were easy to use in Bala-whatever too, so they must be strong in Yu-san Poker as well."
It would be unreasonable to make Yu-san learn new hands now, so your job is to help him by determining whether he can play a "Flush".
Problem Statement
Yu-san has $N$ cards.
Every card has exactly $1$ mark drawn on it, and there are $N+1$ kinds of marks: mark $0$ , mark $1$ , $\dots$ , mark $N$ .
Let the cards he holds be card $1$ , card $2$ , $\dots$ , card $N$ in order. The mark of the $i$-th card ($1\leq i \leq N$) is $A_i$ .
However, immediately before the operation of playing cards described below, each card with mark $0$ can be replaced with a card of any mark among mark $1$, mark $2$ , $\dots$ , mark $N$ .
Now, Yu-san will choose exactly $K$ cards from the cards he holds and play them.
Determine whether he can play cards so that all the played cards have the same mark.
Input
$N\ K$ $A_1\ A_2 \ \dots \ A_N$
Constraints
- $1 \leq K \leq N \leq10^5$
- $0 \leq A_i \leq N\ (1 \leq i\leq N)$
Output
Print Yes if he can play cards with the same mark, and No otherwise.
Print a newline at the end.
Sample
Sample 1
Input
10 5 1 1 1 1 2 2 3 3 4 0
Output
Yes
By replacing the card with mark $0$ with a card with mark $1$ , there will be $5$ cards with mark $1$ .
By playing these $5$ cards, all the played cards have the same mark.
Therefore, the answer is Yes.
Sample 2
Input
5 4 1 2 3 0 0
Output
No
No matter how the cards with mark $0$ are replaced, he cannot play $4$ cards with the same mark.
Sample 3
Input
5 1 1 2 3 4 5
Output
Yes
Whichever card he plays, it counts as playing $1$ card with the same mark.
Sample 4
Input
10 10 0 0 0 0 0 0 0 0 0 0
Output
Yes
All the cards may have mark $0$ .
Sample 5
Input
15 7 0 4 7 3 4 0 8 1 3 4 2 9 0 4 0
Output
Yes
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。