P27624 [洛谷] [Language Monthly Contest 202407] Speech
普及-
题目描述

Problem Background

Once upon a time, there was a glorious kingdom, and Little A was the king. He believed that for the people of his country to communicate, they must have appropriate languages. Therefore, today he intends to bestow speech upon his subjects.

Problem Description

To help everyone become familiar with the new language as quickly as possible, Little A has surveyed the languages used by the $n$ residents of his country.

After the survey, it was found that there are currently $m$ sets of languages (numbered $1, 2, \cdots, m$) in the country, each with $a_i$ grammars, and each resident uses exactly one set of languages (denoted by $b_1, \cdots, b_n$ respectively).

The charm value of a language set is defined as the number of grammars in that language set multiplied by the number of users of that language set. Now, Little A wants to know which language set has the highest charm value.

Input Format

The input consists of three lines.

The first line contains two integers $n, m$, representing the number of residents and the number of language sets, respectively.
The second line contains $m$ integers $a_1, \cdots, a_m$, indicating the number of grammars in each language set.
The third line contains $n$ integers $b_1, \cdots, b_n$, representing the language set number used by each resident.

Output Format

A single line containing an integer, which is the number of the language set with the highest charm value.

If multiple language sets have the highest charm value and they are the same, output the smallest number.

Sample Input and Output

Sample Input #1

3 2
1 2
1 1 2

Sample Output #1

1

Sample Input #2

3 2
1 3
1 1 2

Sample Output #2

2

Sample Input #3

3 1
2 
1 1 1

Sample Output #3

1

Notes

Sample 1 Explanation

  • $2$ people use language set $1$, which has $1$ grammar, so its charm value is $1 \times 2 = 2$.
  • $1$ person uses language set $2$, which has $2$ grammars, so its charm value is $2 \times 1 = 2$.

Since language set $1$ has a smaller number, language set $1$ is chosen.

Sample 2 Explanation

  • $2$ people use language set $1$, which has $1$ grammar, so its charm value is $1 \times 2 = 2$.
  • $1$ person uses language set $2$, which has $3$ grammars, so its charm value is $3 \times 1 = 3$.

Therefore, language set $2$ is chosen.

Data Range

For $20\%$ of the data, $n, m \le 3$.
For another $30\%$ of the data, $m = 1$.
For $100\%$ of the data, $1 \le n, m \le 10^3$, $0 \le a_i \le 10^3$, $1 \le b_i \le m$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

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