您的位置:首页 > 其它

A. Bear and Reverse Radewoosh CodeForces 658A

2016-08-22 20:13 1121 查看
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.

There will be n problems. The i-th problem has initial score pi and it takes exactly ti minutes to solve it. Problems are sorted by difficulty — it's guaranteed that pi < pi + 1 and ti < ti + 1.

A constant c is given too, representing the speed of loosing points. Then, submitting the i-th problem at time x (x minutes after the start of the contest) gives max(0,  pi - c·x) points.

Limak is going to solve problems in order 1, 2, ..., n (sorted increasingly by pi). Radewoosh is going to solve them in order n, n - 1, ..., 1 (sorted decreasingly by pi). Your task is to predict the outcome — print the name of the winner (person who gets more
points at the end) or a word "Tie" in case of a tie.

You may assume that the duration of the competition is greater or equal than the sum of all ti. That means both Limak and Radewoosh will accept all n problems.

Input

The first line contains two integers n and c (1 ≤ n ≤ 50, 1 ≤ c ≤ 1000) — the number of problems and the constant representing the speed of loosing points.

The second line contains n integers p1, p2, ..., pn (1 ≤ pi ≤ 1000, pi < pi + 1) — initial scores.

The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 1000, ti < ti + 1) where ti denotes the number of minutes one needs to solve the i-th problem.

Output

Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points.

Examples

input

3 2

50 85 250

10 15 25

output

Limak

input

3 6

50 85 250

10 15 25

output

Radewoosh

input

8 1

10 20 30 40 50 60 70 80

8 10 58 63 71 72 75 76

output

Tie

Note

In the first sample, there are 3 problems. Limak solves them as follows:

Limak spends 10 minutes on the 1-st problem and he gets 50 - c·10 = 50 - 2·10 = 30 points.

Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85 - 2·25 = 35 points.

He spends 25 minutes on the 3-rd problem so he submits it 10 + 15 + 25 = 50 minutes after the start. For this problem he gets 250 - 2·50 = 150 points.

So, Limak got 30 + 35 + 150 = 215 points.

Radewoosh solves problem in the reversed order:

Radewoosh solves 3-rd problem after 25 minutes so he gets 250 - 2·25 = 200 points.

He spends 15 minutes on the 2-nd problem so he submits it 25 + 15 = 40 minutes after the start. He gets 85 - 2·40 = 5 points for this problem.

He spends 10 minutes on the 1-st problem so he submits it 25 + 15 + 10 = 50 minutes after the start. He gets max(0, 50 - 2·50) = max(0,  - 50) = 0 points.

Radewoosh got 200 + 5 + 0 = 205 points in total. Limak has 215 points so Limak wins.

In the second sample, Limak will get 0 points for each problem and Radewoosh will first solve the hardest problem and he will get 250 - 6·25 = 100 points for that. Radewoosh will get 0 points for other two problems but he is the winner anyway.

In the third sample, Limak will get 2 points for the 1-st problem and 2 points for the 2-nd problem. Radewoosh will get 4 points for the 8-th problem. They won't get points for other problems and thus there is a tie because 2 + 2 = 4.

题意:就是两个人做题,看谁分高,Limak是从前往后做,Radewoosh是从后往前做。第一行输入的是题的数量和一个N,第二行是第几题的分数,第三行是第几题的时间,。这个人获得该题的分数= 该题的分数-(做完这个题的时间+之前做的题的时间)*N。

思路:将它存在多个数组,求出他们的分数之和进行比较

#include<cstdio>
int main()
{
int m,n,i;
int a[1005];
int b[1005];
long long c[1005];
long long d[1005];
long long e[1005];
long long f[1005];
scanf("%d%d",&m,&n);
for(i=0;i<m;i++)
scanf("%d",&a[i]);
for(i=0;i<m;i++)
scanf("%d",&b[i]);
for(i=0;i<m;i++)
{
if(i==0)	c[i]=b[i];
else
c[i]=b[i]+c[i-1];
if(i==0)
{
if(c[i]*n>a[i])	e[i]=0;
else	e[i]=a[i]-c[i]*n;
}
else
{
if(c[i]*n>=a[i])
e[i]=e[i-1];
else
e[i]=a[i]-c[i]*n+e[i-1];
}
}
for(i=m-1;i>=0;i--)
{
if(i==m-1)	d[i]=b[i];
else
d[i]=b[i]+d[i+1];
if(i==m-1)
{
if(d[i]*n>=a[i])	f[m-1]=0;
else	f[m-1]=a[i]-d[i]*n;
}
else
{
if(d[i]*n>a[i])
f[i]=f[i+1];
else
f[i]=a[i]-d[i]*n+f[i+1];
}
}
if(e[m-1]>f[0])	printf("Limak");
else if(e[m-1]<f[0])	printf("Radewoosh");
else	printf("Tie");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: