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

3224번 - grupe 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB69403865.517%

문제

First N positive integers (numbers from 1 to N) are written on the blackboard in some arbitrary order (from left to right).

A group is set of integers which form an interval. For example, sets [2], [4 5] and [3 5 6 4] are groups, but [5 7 2] and [2 4 5] aren't. At the beginning, we assume that each number on the blackboard forms a single group with only itself in it.

There is only one allowed operation - concatenating two adjacent groups, but only if the new set would be a group.

Write a program which will determine wheather sequence of N-1 operations exists, after which all written numbers will be in the same group. If such sequence exists, your program must find at least one of them.

Example (one possible solution for third example):

[6] [3] [2] [1] [4] [5]
[6] [3] [2 1] [4] [5]
[6] [3 2 1] [4] [5]
[6] [3 2 1] [4 5]
[6] [3 2 1 4 5]
[6 3 2 1 4 5] 

입력

In the first line, there will be integer N, 1 ≤ N ≤ 500,000.

In the second line, there will be N positive integers, separated by single space. These numbers are written on the blackboard (i.e. this is an initial state).

출력

In the first line there must be word 'DA' (yes) or 'NE' (no), depending wheather requested sequence exists. If given answer is 'NE', then first line must be the last.

If the written word is 'DA', then the next N–1 lines should consist of two integers a and b so that those numbers in the line (i+1) are the smallest and the biggest number in the group made in i-th gathering.

제한

예제 입력 1

2
2 1

예제 출력 1

DA
1 2

예제 입력 2

6
1 4 2 5 3 6

예제 출력 2

NE

예제 입력 3

6
6 3 2 1 4 5

예제 출력 3

DA
1 2
1 3
4 5
1 5
1 6

힌트

출처

Olympiad > Croatian Highschool Competitions in Informatics > 2004 > Final Exam #1 1번

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

출처

대학교 대회

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

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