[solution] Watching Movies at 2x solution codechef

Watching Movies at 2x solution codechef – Chef started watching a movie that runs for a total of XX minutes.

Chef has decided to watch the first YY minutes of the movie at twice the usual speed as he was warned by his friends that the movie gets interesting only after the first YY minutes.

How long will Chef spend watching the movie in total?

Note: It is guaranteed that YY is even.

Watching Movies at 2x solution codechef

  • The first line contains two space separated integers X,YX,Y – as per the problem statement.

Output Format

  • Print in a single line, an integer denoting the total number of minutes that Chef spends in watching the movie.

Constraints

  • 1X,Y10001≤X,Y≤1000
  • YY is an even integer.

Watching Movies at 2x solution codechef

Subtask #1 (100 points): original constraints

Sample Input 1 

100 20

Sample Output 1 

90

Explanation Watching Movies at 2x solution codechef

For the first Y=20Y=20 minutes, Chef watches at twice the usual speed, so the total amount of time spent to watch this portion of the movie is Y2=10Y2=10 minutes.

For the remaining XY=80X−Y=80 minutes, Chef watches at the usual speed, so it takes him 8080 minutes to watch the remaining portion of the movie.

In total, Chef spends 10+80=9010+80=90 minutes watching the entire movie.

Sample Input 2 

50 24

Watching Movies at 2x solution codechef

 

38

Explanation

For the first Y=24Y=24 minutes, Chef watches at twice the usual speed, so the total amount of time spent to watch this portion of the movie is Y2=12Y2=12 minutes.

For the remaining XY=26X−Y=26 minutes, Chef watches at the usual speed, so it takes him 2626 minutes to watch the remaining portion of the movie.

In total, Chef spends 12+26=3812+26=38 minutes watching the entire movie.

Leave a Comment