ΠΔΠ-32 (2020) - Phase B Junior High School (longsumk)

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem types
Allowed languages
C, C++, Java, Pascal, Python

LET'S PLAN VACATIONS AGAIN

Summer is still far away, but it's time to start planning our vacations for this year. We're counting our money, calculating how much more we will earn until summer, and we conclude that the total amount we can spend for accommodation during our summer vacations is K. However, the price of the room on the island we've been eyeing since last year changes every day, depending on demand. Some days, the good owner gives us the room for free for advertising purposes.

For each of the N days of summer that interest us, we already know the price \mathbf{X_i} of the room on day i (where 1 \le i \le N). Of course, we want to go on vacation for as many days as possible! What is the longest continuous period of days, such that the total cost of the room for those days is exactly equal to K?

Problem

Develop a program in one of the IOI languages (PASCAL, C, C++, Java) that, after reading the values of N and K, as well as the room prices for each day of the time period of interest, will print the maximum number of consecutive days we can go on vacation with the total accommodation cost exactly equal to K.

Input Files:

The input files named longsumk.in are text files with the following structure. The first line contains two integers N and K, separated by a space: the number of days in the time period of interest and the total amount of money we have. The next line contains exactly N non-negative numbers \mathbf{X_i} (for 1 \le i \le N) separated in pairs by a space: the i-th number represents the room price on the i-th day of the period.

Output Files:

The output files named longsumk.out are text files consisting of a single line with a single integer: the maximum number of consecutive days we can go on vacation with a total accommodation cost exactly equal to K. If this is not possible, the number zero should be printed.

Examples of Input - Output Files:
1o

STDIN (longsumk.in)

10 26
14 8 6 12 15 0 11 0 0 11

STDOUT (longsumk.out)

 5
2o

STDIN (longsumk.in)

7 48
29 7 17 9 17 10 5

STDOUT (longsumk.out)

 0
Constraints:
  • 1 \le Ν \le 1.000.000
  • 0 \le Κ \le 1.000.000.000
  • The sum of all \mathbf{X_i} will not exceed 1.000.000.000.
  • Maximum execution time: 1sec.
  • Maximum available memory: 64MB.
Notes:

Formatting: In both the input and the output, each line terminates with a newline character.

Headers in the source code: At the beginning of your source code, you should use the following headers.

(* USER: username
LANG: PASCAL
TASK: longsumk *)

for PASCAL coders

/* USER: username
LANG: C
TASK: longsumk */

for C coders

/* USER: username
LANG: C++
TASK: longsumk */

for C++ coders

/* USER: username
LANG: Java
TASK: longsumk */

for Java coders

# USER: username
# LANG: Python
# TASK: longsumk

for Python coders


Comments

There are no comments at the moment.