#GL0000346. Gây quỹ vì thiên nhiên (Save the Nature)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Gây quỹ vì thiên nhiên (Save the Nature)
Save the Nature
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You have ticket prices and may rearrange the selling order arbitrarily.
The first program receives of a ticket sold at a position divisible by ; the second receives at positions divisible by . A position divisible by both yields in total. Ticket prices are multiples of 100, so every contribution is integral.
Find the smallest number of tickets to sell so that the total donation is at least , or print -1 if it is impossible even after selling all tickets.
PHOJ adaptation: one independent query per input file instead of the multiple-query wrapper of the original Codeforces statement.
Input
Line 1: .
Line 2: prices .
Line 3: .
Line 4: .
Line 5: .
Output
Print the minimum number of tickets, or -1.
Subtasks
- Subtask 1 (20 points): , , , , , , .
- Subtask 2 (30 points): , , , , , , .
- Subtask 3 (50 points): , , , , , , .
Examples
Example 1
Input
8
100 200 100 200 100 200 100 100
10 2
15 3
107
Output
6
Explanation
For the first six tickets, positions 2, 3, 4, 6 contribute. One optimal arrangement obtains 110, while five tickets cannot reach 107.
Example 2
Input
5
200 100 100 100 100
69 5
31 2
90
Output
4
Explanation
Among the first four tickets, positions 2 and 4 receive 31%. Assign prices 200 and 100 to get 93, reaching the target; three tickets do not suffice.