#GD0000199. Sơn số lên hàng rào (Color the Fence)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Sơn số lên hàng rào (Color the Fence)
Color the Fence
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Igor wants to paint the largest possible positive integer on a fence. He has liters of paint. Painting a digit from to requires exactly liters; digit 0 is forbidden.
He may write any sequence of allowed digits as long as the total amount of paint used does not exceed . Digits may repeat, and each occurrence incurs its own cost.
Find the numerically largest integer he can write. A number with more digits is always larger; at equal lengths, the earlier larger digit wins. Print -1 if no digit is affordable.
Input
- The first line contains an integer , the paint budget.
- The second line contains exactly nine positive integers , where is the cost of painting digit once.
Output
If at least one digit is affordable, print a single line containing the decimal digits of the largest possible integer without spaces or 0. Otherwise print exactly -1.
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
5
5 4 3 2 1 2 3 4 5
Output
55555
Explanation
The budget is . Digit 5 costs , so five copies produce 55555. Since every digit costs at least , a six-digit number is impossible. At length five, each digit must cost ; digit 5 is the largest affordable choice at that cost. Thus 55555 is optimal.