TLE '16 Contest 2 P3 - Fax's Thanksgiving Dinner

View as PDF

Submit solution


Points: 10 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type
Fax McClad is about to cut the giant space turkey.

It is not well known that Cronerians also celebrate Thanksgiving as well! Today, Fax McClad, Croneria's most grateful bounty hunter, is celebrating by eating dinner with N family members!

The main course of the dinner is a giant space turkey (which his wingmate Flaco would strongly protest against eating). Fax is responsible for carving the space turkey into pieces for his family members to eat. Initially, the space turkey is in one giant piece. Fax can make C different types of cuts; by using the i^\text{th} cut, Fax can split a single piece into c_i smaller pieces. Each individual cut can be done many times.

However, making an infinite number of cuts is too time-consuming, so Fax McClad will never form infinitely small pieces of space turkey.

Fax's family members are particularly picky! The j^\text{th} family member would like pieces of turkey that sum up to exactly \frac{1}{n_j} of the entire space turkey. Pieces of turkey cannot be shared. Please help Fax determine if it is possible to satisfy all of his guests!

Input Specification

The first line of input will contain N and C (1 \le N, C \le 1\,000).

C lines of input follow; the i^\text{th} line will contain c_i (2 \le c_i \le 10^6).

N lines of input follow; the j^\text{th} line will contain n_j (2 \le n_j \le 10^6). It is guaranteed that the sum of all \frac{1}{n_j} will not exceed 1.

For 40% of the points, 1 \le N, C \le 100, 2 \le c_i \le 10\,000, and 2 \le n_j \le 15.

Output Specification

Output Y if Fax can satisfy all of his guests and N otherwise.

Sample Input 1

2 2
2
3
2
6

Sample Output 1

Y

Explanation for Sample Output 1

Fax can first cut the turkey into thirds. Then, he can take two of the thirds and cut each of them into half, giving one sixth of the turkey to the 2nd guest and 3 sixths (one half) of the turkey to the 1st guest.

Sample Input 2

2 2
2
3
2
5

Sample Output 2

N

Explanation for Sample Output 2

No matter how Fax cuts the turkey, he cannot form pieces that total to 1/5 of the turkey.

Note that Fax cannot cut the turkey into infinite pieces in order to give the 2nd guest 1/5 of the turkey.


Comments


  • 21
    jlsajfj  commented on Oct. 20, 2016, 6:30 p.m.

    The name should be "Fax's-giving Dinner"