#QHD0000070. Hệ tiền chuẩn tắc (Canonical Coin Systems)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Hệ tiền chuẩn tắc (Canonical Coin Systems)
Canonical Coin Systems
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A coin system consists of strictly increasing, distinct denominations , with , and unlimited supply of each coin. A greedy cashier repeatedly chooses the largest denomination not exceeding the remaining amount.
A system is canonical if this greedy algorithm uses the minimum possible number of coins for every positive integer amount. It is non-canonical if at least one counterexample exists. For example, with denominations , amount is a counterexample: greedy uses while two coins suffice.
Determine whether the input system is canonical. Print only the required lowercase word; no counterexample or coin list is requested. Your algorithm must justify checking a finite, sufficient range rather than an arbitrary set of small amounts.
Input
The first line contains . The second line contains the strictly increasing denominations .
Output
Print canonical if greedy is always optimal, otherwise print non-canonical.
Subtasks
- Subtask 1 (20 points): ; ; unlimited coins of every denomination.
- Subtask 2 (30 points): ; ; unlimited coins of every denomination.
- Subtask 3 (50 points): ; ; unlimited coins of every denomination.
Examples
Input
3
1 3 4
Output
non-canonical
Explanation
At amount , greedy returns (three coins), but uses only two. Thus a counterexample exists.