EIU ICPC Contest 2026 - G: Ant Colony

Xem dạng PDF

Gửi bài giải

Điểm: 1,00
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 256M
Input: stdin
Output: stdout

Nguồn bài:
Châu Nhật Tăng
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

In a faraway land, a colony of ants is busy constructing a new nest. According to the engineer ant's blueprint, the worker ants must dig ~N - 1~ tunnels connecting ~N~ chambers such that every chamber is reachable from any other chamber.

Furthermore, to align with the colony's "feng shui", each chamber ~u~ must have a maximum distance to its farthest chamber equal to exactly ~A_u~ (the distance between two chambers is defined as the number of tunnels on the shortest path between them).

Is it possible to build a nest that meets all these requirements? Help the engineer ant check if such a structure can be built!

Input

  • The first line contains a positive integer ~N~ ~(1 \le N \le 10^5)~ — the number of chambers in the nest.
  • The second line contains ~N~ integers ~A_1, A_2, \dots, A_N~ ~(1 \le A_i < N)~ — where ~A_u~ represents the distance from chamber ~u~ to its farthest chamber.

Output

  • Print Possible if such a nest can be constructed. Otherwise, print Impossible.

Sample Input 1

5
3 2 2 3 3

Sample Output 1

Possible

Sample Input 2

3
1 1 2

Sample Output 2

Impossible


Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.