Programming contests

ECN programozó csapatverseny, 2018. május 12.

May 12, 2018 10:15 AM – May 12, 2018 3:15 PM

Server

You are in charge of a server that needs to run some submitted tasks on a first-come, first-served basis. Each day, you can dedicate the server to run these tasks for at most T minutes. Given the time each task takes, you want to know how many of them will be finished today.

Consider the following example. Assume T = 180 and the tasks take 45, 30, 55, 20, 80, and 20 minutes (in the order they are submitted). Then, only four tasks can be completed. The first four tasks can be completed because they take 150 minutes, but not the first five, because they take 230 minutes which is greater than 180. Notice that although there is enough time to perform the sixth task (which takes 20 minutes) after completing the fourth task, you cannot do that, because the fifth task is not done yet.

Input Specification

The input consists of a single test case. The first line contains two integers n and T, where 1 ≤ n ≤ 50 is the number of tasks, and 1 ≤ T ≤ 500. The next line contains n positive integers not greater than 100, indicating how long each task takes, in the order they are submitted.

Output Specification

Display the number of tasks that can be completed in T minutes on a first-come, first-served basis.

Sample Input 1

  1. 6 180
  2. 45 30 55 20 80 20
download as text file

Output for Sample Input 1

  1. 4
download as text file

Sample Input 2

  1. 10 60
  2. 20 7 10 8 10 27 2 3 10 5
download as text file

Output for Sample Input 2

  1. 5
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019