TLE '17 Contest 2 P2 - Unlucky Numbers

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 2.0s
Python 4.0s
Memory limit: 256M

Author:
Problem type
The bright red buildings and skies of the University of Fireloo.

The University of Fireloo is about to build a new on-campus residence named University of Fireloo Place (UFP), a village with N apartment buildings!

Apparently, UFP's architects are quite superstitious, so they believe that the K distinct numbers u1,,uK are "unlucky". As a result, for the ith apartment building, they want the floors to be numbered from 1 to fi inclusive, but removing all floors with unlucky floor numbers.

Now, the architects need your help to determine how many floors each apartment in UFP should really have.

Constraints

1N1000000
1K500000
1fi1000000 (i=1,,N)
1uj1000000 (j=1,,K)

For 20% of the points, N,fi,uj100, and K10 for all i and j.

For an additional 30% of the points, N,fi,uj100000, and K10000 for all i and j.

Input Specification

The first line contains K, the number of unlucky numbers the architects have considered.

The second line contains distinct, space-separated positive integers u1,,uK, the unlucky numbers.

The third line contains N, the number of apartments to be built in UFP.

For the next N lines, the ith line contains fi, the top floor number of the ith apartment. It is guaranteed that no top floor number is an unlucky number.

Output Specification

Output N lines, where the ith line contains one integer denoting the actual number of floors the ith apartment should have.

Sample Input

Copy
2
4 13
2
16
14

Sample Output

Copy
14
12

Comments


  • 0
    Tearful  commented on Nov. 1, 2017, 11:12 p.m.

    Someone please tell me what I can do to make my code run faster :v


    • 1
      unsuspiciouscrumpet  commented on Nov. 2, 2017, 12:11 a.m.

      You need to change your approach to the question since your current time complexity is too large. You can read the editorial for a hint.