Codeforces 750A New Year and Hurry Solution & Explanation

Difficulty : 800

Problem Description

Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n is the hardest. Limak knows it will take him 5·i minutes to solve the i-th problem.

Limak’s friends organize a New Year’s Eve party and Limak wants to be there at midnight or earlier. He needs k minutes to get there from his house, where he will participate in the contest first.

How many problems can Limak solve if he wants to make it to the party?

Input

The only line of the input contains two integers n and k (1 ≤ n ≤ 10, 1 ≤ k ≤ 240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.

Output

Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.

Examples

Input3 222
Output2
Input4 190
Output4
Input7 1
Output7

Note

In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn’t have enough time to solve 3 problems so the answer is 2.

In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.

In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems.


Solution

If the number of problems is large, exceeding a range suitable for iteration, it might be necessary to consider using mathematical methods for calculation.

However, since this particular problem specifies that there are only up to 10 problems, and considering the additional constraints, it is appropriate to use a loop for calculation.

In our solution, we first calculate the remaining time. From 20:00 to midnight is 240 minutes, and we need to subtract k minutes to account for Limak’s travel time to the party. Therefore, we will have 240 – k minutes available.

Then, we iterate through each problem in a loop, calculating the available time Limak has after solving each problem. If the remaining time becomes negative, it indicates that Limak doesn’t have enough time to solve the next problem. In this case, we record the number of problems already solved, cnt, and set found to true, then exit the loop.

C# Solution

Solution1

string[] arr = Console.ReadLine().Split(" ");
int n = int.Parse(arr[0]);
int k = int.Parse(arr[1]);


int left = 240-k;
int cnt = 0;
bool found = false;

for(int i=0; i<n; i++){
    left -= (i+1)*5;
    
    if(left<0){
        cnt=i;
        found = true;
        break;
    }
}

Console.WriteLine(found ? cnt : n);

If found is false, it means Limak will still have time after solving all the problems.


Conclusion

If it were me, I would just go to the party without solving any problems at all 🫣🫣🫣

🧡If my solution helps, that is my honor!

🧡You can support me by sharing my posts, thanks you~~

✅If you got any problem about the explanation or you need other programming language solution, please feel free to let me know !!

The problem link : Problem – 750A – Codeforces

Random Codeforces Posts

Leave a Reply

Your email address will not be published. Required fields are marked *