CF746C.Tram

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The tram in Berland goes along a straight line from the point 00 to the point ss and back, passing 11 meter per t1t_{1} seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x=0x=0 and x=sx=s .

Igor is at the point x1x_{1} . He should reach the point x2x_{2} . Igor passes 11 meter per t2t_{2} seconds.

Your task is to determine the minimum time Igor needs to get from the point x1x_{1} to the point x2x_{2} , if it is known where the tram is and in what direction it goes at the moment Igor comes to the point x1x_{1} .

Igor can enter the tram unlimited number of times at any moment when his and the tram's positions coincide. It is not obligatory that points in which Igor enter and exit the tram are integers. Assume that any boarding and unboarding happens instantly. Igor can move arbitrary along the line (but not faster than 11 meter per t2t_{2} seconds). He can also stand at some point for some time.

输入格式

The first line contains three integers ss , x1x_{1} and x2x_{2} ( 2<=s<=10002<=s<=1000 , 0<=x1,x2<=s0<=x_{1},x_{2}<=s , x1x2x_{1}≠x_{2} ) — the maximum coordinate of the point to which the tram goes, the point Igor is at, and the point he should come to.

The second line contains two integers t1t_{1} and t2t_{2} ( 1<=t1,t2<=10001<=t_{1},t_{2}<=1000 ) — the time in seconds in which the tram passes 11 meter and the time in seconds in which Igor passes 11 meter.

The third line contains two integers pp and dd ( 1<=p<=s11<=p<=s-1 , dd is either 11 or ) — the position of the tram in the moment Igor came to the point x1x_{1} and the direction of the tram at this moment. If , the tram goes in the direction from the point ss to the point 00 . If d=1d=1 , the tram goes in the direction from the point 00 to the point ss .

输出格式

Print the minimum time in seconds which Igor needs to get from the point x1x_{1} to the point x2x_{2} .

输入输出样例

  • 输入#1

    4 2 4
    3 4
    1 1
    

    输出#1

    8
    
  • 输入#2

    5 4 0
    1 2
    3 1
    

    输出#2

    7
    

说明/提示

In the first example it is profitable for Igor to go by foot and not to wait the tram. Thus, he has to pass 22 meters and it takes 88 seconds in total, because he passes 11 meter per 44 seconds.

In the second example Igor can, for example, go towards the point x2x_{2} and get to the point 11 in 66 seconds (because he has to pass 33 meters, but he passes 11 meters per 22 seconds). At that moment the tram will be at the point 11 , so Igor can enter the tram and pass 11 meter in 11 second. Thus, Igor will reach the point x2x_{2} in 77 seconds in total.

首页