Log inSign up
Problems / B118

Delivery period

300 ptsCases 15Set by dongbinna
Added October 30.
1 solved1 attempted1 submissionssolvers took 1.0 tries on average

Statement

A factory wrote down, in date order, how many parts it made each day over N days. The number of parts made on each day from day 1 to day N is a natural number, and there is no day on which it made none.

The factory has to deliver the S parts it was ordered in one shipment. Because of the room in the warehouse, though, only the parts made over a run of days in a row can go out as one load. In other words it has to pick a period of dates that is not broken, such as day i through day j, and ship every part made in that period. Shipping more parts than S is fine.

The plant manager wants to use the warehouse for as short a time as possible, so among the periods that cover the order they want to pick the one with the fewest days.

Write a program that takes the production log and the order size S, and computes the number of days in the shortest period of days in a row whose parts come to S or more.

For example, suppose the production log for N=10 days is given by the table below, and S=15.

Day12345678910
Parts made51351074928

One day alone cannot cover 15 parts. Even the best day is day 5 with only 10. So two-day periods have to be looked at. Comparing a few two-day periods gives the table below.

PeriodDay 4 through day 5Day 5 through day 6Day 7 through day 8
Parts made5 and 1010 and 74 and 9
Total151713
Order coveredCoveredCoveredNot covered

The two days from day 4 to day 5 come to exactly 15, which covers the order. Day 5 to day 6 covers it too, with 17. One day cannot cover the order and two days can, so the answer for this case is 2.

Input and Output Examples

Example 1

Input

10 15
5 1 3 5 10 7 4 9 2 8

Output

2

Example 2

Input

3 852
430 2107 3679

Output

1

Example 3

Input

5 2126
3139 1433 4375 6042 5320

Output

1

Input

  • The first line holds the number of recorded days N and the order size S, separated by a space. N is a natural number from 1 to 100,000. S is a natural number from 1 to 1,000,000,000.

  • The second line holds the number of parts made from day 1 to day N, separated by spaces, all on one line. Each day's number of parts is a natural number from 1 to 10,000.

  • The whole input is at most about 0.5MB. One line can hold up to 100,000 numbers, so read the input line by line and split each line on whitespace.

Output

  • Print the number of days in the shortest period whose parts come to S or more on the first line. If even all N days together cannot cover S, print 0.

Requirements

  • Only a period whose dates run without a break can be picked
  • Shipping more parts than S is allowed. S or more is enough
  • A period made of one day alone can be picked
  • Every day's number of parts is at least 1
  • If even all N days together cannot cover S, print 0
  • You must write a program that reads from standard input and writes to standard output
  • Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
  • The languages you can use are Python and JavaScript
  • The memory limit is 256MB. The browser does not measure it, it only states it
  • The time limit is set by measuring the setter's reference solution on the same runtime
  • On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
  • The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
  • There are 15 cases, and 3 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
  • You have to pass all 15 cases to solve this.
Read the requirements carefully before solving. Tampering with the grading to make a submission look like a pass can get you sanctioned if caught. The code you submit is published on the leaderboard along with the result.

Examples

3 public cases. Judging also uses hidden cases. You have to pass all 15 cases to solve this.

Input
Expected output
3 852
430 2107 3679
1
5 2126
3139 1433 4375 6042 5320
1
10 15
5 1 3 5 10 7 4 9 2 8
2

Solution

Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.

0 chars1 lineMemory 256MB (recorded only)Reference 26ms

Submitting requires you to log in. Running against the public cases works without one.

You can test with 3 public cases. Submitting runs the hidden cases too.

People who solved this problem

The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.

1bampal2345ms347 charsPythonWindows NT 10.0 / Chrome/156.0.0.0 / 8코어 / 16GB

Log in and you can see the code once you solve this problem.