P27625 [洛谷] [Language Monthly Contest 202407] Rules
普及-
题目描述

Problem Background

Once upon a time, there was a glorious kingdom, and Little A was its king. He believed that a country needed not only laws but also some customary rules. Therefore, today he decided to bestow his rules upon the kingdom.

Problem Description

Little A has established several rules, each with a code that is a non-negative integer not exceeding $10^9$.

There are $n$ residents in Little A's kingdom, and each resident adheres to exactly one rule every day. Little A has recorded the rule codes followed by each resident over $m$ days.

Now, Little A wants to assess whether the rule with code $k$ aligns with the will of the people. The assessment method is as follows:
- If on a given day, more than half of the people follow rule $k$, then Little A considers rule $k$ to be in line with the will of the people on that day.
- If rule $k$ is in line with the will of the people on more than half of the days, then he considers rule $k$ to be correct. Otherwise, he considers rule $k$ to be incorrect.

If Little A's rule $k$ is correct, please output YES; otherwise, output NO.

Input Format

The first line contains three integers $n, m, k$, representing the total number of residents, the number of recorded days, and the code of the rule Little A wants to assess, respectively.

The following $m$ lines each contain $n$ integers, representing the rule codes followed by each resident on each day.

Output Format

A single line containing the string YES or NO to indicate whether Little A's rule $k$ is considered correct.

Sample Input and Output

Sample Input #1

3 2 1
1 1 2
3 1 2

Sample Output #1

YES

Sample Input #2

2 2 1
1 2
2 1

Sample Output #2

YES

Sample Input #3

3 2 1
9 9 8
1 9 9

Sample Output #3

NO

Notes

Sample 1 Explanation

  • On the first day, 2 people follow rule 1, which is more than half of the total number of residents, so rule 1 is in line with the will of the people on the first day.
  • On the second day, only 1 person follows rule 1, which is less than half of the total number of residents, so rule 1 is not in line with the will of the people on the second day.

Since there is 1 day where rule 1 is in line with the will of the people, which is equal to half of the total number of days, Little A considers his rule to be correct.

Sample 2 Explanation

On both the first and second days, 1 person follows rule 1, which is exactly half of the total number of residents. Therefore, on both days, rule 1 is in line with the will of the people, so Little A considers his rule to be correct.

Sample 3 Explanation

  • On the first day, no one follows rule 1, so rule 1 is not in line with the will of the people on the first day.
  • On the second day, only 1 person follows rule 1, which is less than half of the total number of residents, so rule 1 is not in line with the will of the people on the second day.

Since there is no day where rule 1 is in line with the will of the people, Little A considers his rule to be incorrect.

Data Range

  • For $20\%$ of the data, $m = 1$.
  • For another $20\%$ of the data, $n = 1$.
  • For $100\%$ of the data, $1 \le n, m \le 1000$, $0 \leq k \leq 10^9$, and all input data $x$ satisfy $0 \leq x \leq 10^9$.
输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 2 1 1 1 2 3 1 2
样例输出
YES