# A. Is it rated?

## 原题

Is it rated?

Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.

Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.

It’s known that if at least one participant’s rating has changed, then the round was rated for sure.

It’s also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant’s rating has changed.

In this problem, you should not make any other assumptions about the rating system.

Determine if the current round is rated, unrated, or it’s impossible to determine whether it is rated of not.

### Input

The first line contains a single integer $n$ $(2 ≤ n ≤ 1000)$ — the number of round participants.

Each of the next n lines contains two integers $a_i$ and $b_i$ $(1 ≤ a_i, b_i ≤ 4126)$ — the rating of the i-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.

### Output

If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it’s impossible to determine whether the round is rated or not, print "maybe".

• input
• output
• input
• output
• input
• output

### Note

In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.

In the second example, no one’s rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone’s rating would’ve changed for sure.

In the third example, no one’s rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it’s impossible to determine whether the round is rated or not.

## 思路

• 根据题目的意思，如果有人的分数发生了变化，则一定是评级过的；而如果分数都是一样的，检查是否是降序排列，如果不是，则没有进行评级，否则便无法确定。

# B. T-Shirt Hunt

## 原题

Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt.

Unfortunately, you didn’t manage to get into top 25, but you got into top 500, taking place $p$.

Now the elimination round of 8VC Venture Cup 2017 is being held. It has been announced that the Codecraft-17 T-shirt winners will be chosen as follows. Let s be the number of points of the winner of the elimination round of 8VC Venture Cup 2017. Then the following pseudocode will be executed:

Here "div" is the integer division operator, "mod" is the modulo (the remainder of division) operator.

As the result of pseudocode execution, 25 integers between 26 and 500, inclusive, will be printed. These will be the numbers of places of the participants who get the Codecraft-17 T-shirts. It is guaranteed that the 25 printed integers will be pairwise distinct for any value of s.

You’re in the lead of the elimination round of 8VC Venture Cup 2017, having x points. You believe that having at least y points in the current round will be enough for victory.

To change your final score, you can make any number of successful and unsuccessful hacks. A successful hack brings you 100 points, an unsuccessful one takes 50 points from you. It’s difficult to do successful hacks, though.

You want to win the current round and, at the same time, ensure getting a Codecraft-17 T-shirt. What is the smallest number of successful hacks you have to do to achieve that?

### Input

The only line contains three integers $p$, $x$ and $y$ $(26 ≤ p ≤ 500; 1 ≤ y ≤ x ≤ 20000)$ — your place in Codecraft-17, your current score in the elimination round of 8VC Venture Cup 2017, and the smallest number of points you consider sufficient for winning the current round.

### Output

Output a single integer — the smallest number of successful hacks you have to do in order to both win the elimination round of 8VC Venture Cup 2017 and ensure getting a Codecraft-17 T-shirt.

It’s guaranteed that your goal is achievable for any valid input data.

• input
• output
• input
• output
• input
• output
• input
• output
• input
• output

### Note

In the first example, there is no need to do any hacks since 10880 points already bring the T-shirt to the 239-th place of Codecraft-17 (that is, you). In this case, according to the pseudocode, the T-shirts will be given to the participants at the following places:

475 422 84 411 453 210 157 294 146 188 420 367 29 356 398 155 102 239 91 133 365 312 449 301 343


In the second example, you have to do two successful and one unsuccessful hack to make your score equal to 7408.

In the third example, you need to do as many as 24 successful hacks to make your score equal to 10400.

In the fourth example, it’s sufficient to do 6 unsuccessful hacks (and no successful ones) to make your score equal to 6500, which is just enough for winning the current round and also getting the T-shirt.

## 思路

• 暴力搜索
• 只要可以保证$x>y$,就能一直减50分; 然后看看你的分数能不能让你在第$p$名拿到奖品; 这种情况下,成功hack次数都为0。
• 否则,每次考虑hack成功一次以及hack成功和失败各一次的情况。

# C. Success Rate

## 原题

You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to $x / y$.

Your favorite rational number in the $[0;1]$ range is $p / q$. Now you wonder: what is the smallest number of submissions you have to make if you want your success rate to be $p / q$?

### Input

The first line contains a single integer $t$ $(1 ≤ t ≤ 1000)$ — the number of test cases.

Each of the next t lines contains four integers $x$, $y$, $p$ and $q$ $(0 ≤ x ≤ y ≤ 10^9; 0 ≤ p ≤ q ≤ 10^9; y > 0; q > 0)$.

It is guaranteed that $p / q$ is an irreducible fraction.

Hacks. For hacks, an additional constraint of $t ≤ 5$ must be met.

### Output

For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.

• input
• output

### Note

In the first example, you have to make 4 successful submissions. Your success rate will be equal to $7 / 14$, or $1 / 2$.

In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to $9 / 24$, or $3 / 8$.

In the third example, there is no need to make any new submissions. Your success rate is already equal to $20 / 70$, or $2 / 7$.

In the fourth example, the only unsuccessful submission breaks your hopes of having the success rate equal to $1$.

## 思路

• 题目意思为$$(x+a)/(y+b)=p/q$$

$$x+a=np$$$$y+b=nq$$
于是
$$a=np-x$$$$b=nq-y$$
• 可以得出，当$n$增大时，$a,b$也单调增加。
• 可以使用二分法求得$n$的值从而计算出$b$。

# D. Dynamic Problem Scoring

## 原题

Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.

For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.

solvers fraction Maximum point value
$(1/2,1]$ $500$
$(1/4,1/2]$ $1000$
$(1/8,1/4]$ $1500$
$(1/16,1/8]$ $2000$
$(1/32,1/16]$ $2500$
$[0,1/32]$ $3000$

Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to $1 / 4$, and the problem’s maximum point value is equal to 1500.

If the problem’s maximum point value is equal to $x$, then for each whole minute passed from the beginning of the contest to the moment of the participant’s correct submission, the participant loses $x / 250$ points. For example, if the problem’s maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with $2000·(1 - 40 / 250) = 1680$ points for this problem.

There are $n$ participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It’s also possible that this participant made no submissions to this problem.

With two seconds until the end of the round, all participants’ submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.

Unfortunately, Vasya is a cheater. He has registered $10^9 + 7$ new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn’t solved.

Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn’t want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.

Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya’s assumptions are correct), or report that Vasya can’t achieve his goal.

### Input

The first line contains a single integer $n$ $(2 ≤ n ≤ 120)$ — the number of round participants, including Vasya and Petya.

Each of the next $n$ lines contains five integers $a_{i, 1}, a_{i, 2}…, a_{i, 5}$ $( - 1 ≤ a_{i, j} ≤ 119)$ — the number of minutes passed between the beginning of the round and the submission of problem $j$ by participant $i$, or -1 if participant $i$ hasn’t solved problem $j$.

It is guaranteed that each participant has made at least one successful submission.

Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.

### Output

Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can’t achieve his goal.

• input
• output
• input
• output
• input
• output
• input
• output

## 思路

• 暴力搜索
• 枚举有$k$人加入作弊，根据题目要求可以得到贪心方案：
• 对于自己做得快的题，让这道题的解决率变低，让这题价值变高，即这$k$个人都没做对；
• 对于自己做得慢的题，让这道题的解决率变高，让这题价值变低，即这$k$个人都做对；
• 对于你自己都没做对的题，这$k$人也没法做对。
• 注意搜索退出条件不需要很大（不然遇到无解会超时），当人数超过现有人数32倍的时候，再增加人数也对得分没有影响了。

0%