7036.Two Array Average

Time Limit: 1s Memory Limit: 512MB

You are given two arrays of $n$ integers.

Your task is to select a nonempty prefix from both arrays such that the average of all selected numbers is as large as possible.

Input Format(From the terminal/stdin)

The first line has an integer $n$ .

The second line has $n$ integers $a_1,a_2,\dots,a_n$ : the numbers in the first array.

The third line has $n$ integers $b_1,b_2,\dots,b_n$ : the numbers in the second array.

  • $1 \le n \le 10^5$
  • $1 \le a_i, b_i \le 10^9$

Output Format(To the terminal/stdout)

Print two numbers: the prefix sizes.

Your answer is considered correct if the absolute or relative difference to the maximum average is at most $10^{-6}$ .

Sample Input

Copy
4
1 5 5 2
3 1 3 1
 \n
 · · · \n
 · · · \n

Sample Output special judge

Copy
3 1
 · \n

if you choose the prefixes $[1,5,5]$ and $[3]$ , the average is $(1+5+5+3)/4=3.5$ which is the maximum possible average.

Source: CSES, Additional Problems I, 3361

Submit

请先 登录

© 2025 FAQs