#P9740. 「KDOI-06-J」ION 比赛

    ID: 10812 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 1 上传者: 标签>数学2023洛谷原创O2优化枚举洛谷月赛

「KDOI-06-J」ION 比赛

Problem Description

In the ION Contest, there are a total of nn problems. The full score for each problem is 100100 points.

Problem ii has aia_i test points, and all test points in this problem have the same value, so aia_i must be a divisor of 100100. For each test point you pass, you will get the score equal to the value of that test point.

By some technical means, you learned that this year's Au cutoff score in the ION Contest is tt points.

Now, in problem ii, you have already passed bib_i test points. As a strategic contestant, you want to know: for any 1jn1\le j\le n, if you spend all the remaining contest time grinding only problem jj (and do no other problems), what is the minimum number of additional test points you need to pass to get Au, that is, to make your total score t\ge t.

Of course, you may be unable to turn the tables (get Au) by grinding a certain problem. In that case, you need to output NaN.

Input Format

Read input from standard input.

The first line contains a positive integer nn, representing the total number of problems.

The next nn lines each contain two non-negative integers ai,bia_i, b_i, representing the number of test points in problem ii and the number of test points you have already passed. It is guaranteed that aia_i is a divisor of 100100 and biaib_i \le a_i.

The last line contains an integer tt, representing the Au cutoff score.

Output Format

Write output to standard output.

If your score has already reached the Au cutoff, output one line with the string Already Au..

Otherwise, output nn lines. In line ii, output one of the following two formats:

  • A positive integer cic_i, meaning the minimum number of additional test points you need to pass in problem ii to get Au.
  • The string NaN, meaning you cannot turn the tables (get Au) through this problem.
7
100 100
20 20
25 23
25 10
20 14
25 11
20 0
447
NaN
NaN
1
1
1
1
1
7
100 100
20 20
25 23
25 10
20 14
25 11
20 0
446
Already Au.
7
100 100
20 20
20 10
25 13
20 20
25 16
20 6
509
NaN
NaN
3
4
NaN
4
3
7
100 100
20 19
20 20
25 11
20 20
25 25
20 6
509
Already Au.

Hint

[Sample Explanation #1]

It is easy to see that the current score is 100+100+92+40+70+44=446100+100+92+40+70+44=446, and the cutoff score is 447447. Therefore, in any problem where you have not gotten full marks, passing one more test point is enough.

[Constraints]

For all testdata, it is guaranteed that: 1n71\leq n\leq 7, 0biai0\leq b_i\leq a_i, 1ai1001\leq a_i\leq 100 and aia_i is a divisor of 100100, 0t100n0\leq t\leq 100n.

Test Point ID nn aia_i Special Property
11 7\leq7 100\leq100 Guarantees that the current score is greater than or equal to tt
232\sim3 =1=1 None
454\sim5 7\leq7 =100=100
6106\sim10 100\leq100

Translated by ChatGPT 5