Logo
(追記) (追記ここまで)

33724번 - Grid Coloring 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB90343439.080%

문제

President K is designing a pattern represented by a grid with $N$ rows and $N$ columns. To achieve this, he has decided to paint each cell with a color represented by an integer number. Let us refer to the cell in the $i$-th row (1ドル ≤ i ≤ N$) and $j$-th column (1ドル ≤ j ≤ N$) as cell $(i, j)$.

Currently, the cells in the first column and first row are already painted. Specifically, cell $(i, 1)$ (1ドル ≤ i ≤ N$) is painted with color $A_i$ and cell $(1, j)$ (1ドル ≤ j ≤ N$) is painted with color $B_j$. Note that $A_1 = B_1$.

For the remaining unpainted cells, President K is going to paint them by the following procedure:

  • For each $i = 2, 3, \dots , N$ in order, paint the cells in the $i$-th row as follows:
    • For each $j = 2, 3, \dots , N$ in order, paint cell $(i, j)$ with the color that has the larger number between:
      • The color of cell $(i - 1, j),ドル and
      • The color of cell $(i, j − 1)$.
    • If both colors have the same number, paint the cell with that color.

President K would like to determine the color that is painted on the largest number of cells after all $N^2$ cells have been painted, as well as the number of cells painted with that color.

Write a program that, given the size of the grid and the color information for the first column and first row, determines the color number painted on the largest number of cells and the number of cells painted with that color. If multiple colors are painted on the largest number of cells, output the largest color number among them.

입력

Read the following data from the standard input.

$N$

$A_1$ $A_2$ $\cdots$ $A_N$

$B_1$ $B_2$ $\cdots$ $B_N$

출력

Write one line to the standard output containing two integers separated by a space:

  1. The color number that is painted on the largest number of cells, and
  2. The number of cells painted with that color.

If multiple colors are painted on the largest number of cells, output the largest color number among them.

제한

  • 2ドル ≤ N ≤ 200,円 000$.
  • 1ドル ≤ A_i ≤ 10^9$ (1ドル ≤ i ≤ N$).
  • 1ドル ≤ B_j ≤ 10^9$ (1ドル ≤ j ≤ N$).
  • $A_1 = B_1$.
  • Given values are all integers.

서브태스크

번호배점제한
115

$N ≤ 500,ドル $A_i ≤ 100,円 000$ (1ドル ≤ i ≤ N$), $B_j ≤ 100,円 000$ (1ドル ≤ j ≤ N$).

210

$N ≤ 500$.

320

$A_i ≤ 2$ (1ドル ≤ i ≤ N$), $B_j ≤ 2$ (1ドル ≤ j ≤ N$).

425

$A_i < A_{i+1}$ (1ドル ≤ i ≤ N − 1$), $B_j < B_{j+1}$ (1ドル ≤ j ≤ N − 1$).

530

No additional constraints.

예제 입력 1

3
5 2 5
5 3 1

예제 출력 1

5 4

In this sample, the color of each cell in the grid will be as follows:

The color number painted on the largest number of cells is 5ドル,ドル which appears on 4ドル$ cells. Thus, print 5ドル$ and 4ドル$ in this order, separated by a space.

This sample input satisfies the constraints of Subtasks 1, 2, and 5.

예제 입력 2

3
1 7 8
1 3 5

예제 출력 2

8 3

In this sample, the color of each cell in the grid will be as follows:

The color numbers painted on the largest number of cells are 7ドル$ and 8ドル,ドル each painted on 3ドル$ cells. In this case, output the larger color number, 8ドル,ドル followed by the number of cells, 3ドル,ドル separated by a space.

This sample input satisfies the constraints of Subtasks 1, 2, 4, and 5.

예제 입력 3

4
2 1 2 1
2 1 1 2

예제 출력 3

2 10

This sample input satisfies the constraints of Subtasks 1, 2, 3, and 5.

힌트

출처

Olympiad > Japanese Olympiad in Informatics > JOI 2024/2025 1번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /