Ok Google, play despacito

Bhavesh loves to listen to music while walking his way to attend boring lectures in his college.

He has a playlist of songs which has all songs of equal length, L. (in seconds)

One day while going on his way, he decided to calculate his average walking speed and he comes to know that he walks at a speed of 0.5 m/s.

You will be given the distance D, he has to walk down to reach his class, after which he stops the music.

You have to find the minimum number of songs he needs to add to his playlist so as the music plays in the whole path.

Example:

Input:  l = 11, d = 440
Output: 80

Approach

C++

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int l = 11d = 440;

    int ans = (2 * d) / l;
    int x = 2 * d;
    if (x % l == 0)
        cout << ans << "\n";
    else
        cout << ans + 1 << "\n";
    return 0;
}


No comments:

Post a Comment