Huawei OD machine test real questions-Maximum number of gems to buy-2023 OD Unified Examination (Paper C)

Topic description:

There is a row of gems in the window. Different gems correspond to different prices. The price of gems is marked as gems[i],0<=i<n, n = gems.length gems can be sold at the same time. 0 or more gems can be sold at the same time. If many gems are sold at the same time, , the gems sold are required to have consecutive numbers; for example, the maximum number of gems purchased by a customer is m, and the gem numbers purchased must be gems[i],gems[i+1]...gems[i+m-1](0< ;=i<n,m<=n) Assuming that you currently have money with a total face value of value, how many gems can you buy at most? If you cannot buy gems, 0 will be returned.

Input description: Enter n in the first line, parameter type is int, value range: [0,10], indicating the total number of gems in the window.

The next n lines respectively represent the prices from the 0th to the n-1th gem, that is, the price from gems[0] to gems[n-1]. The type is int and the value range is: (0,1000].

Enter v in the next line, type is int, value range: [0,10] represents the money you have.

Output description: Output a return value of type int, indicating the maximum number of gems that can be purchased.

Example 
Example 1

Input: 7

          8

          4

          6

          3

          1

          6

          7

         10

Output: 3

illustrate:

        gems = [8,4,6,3,1,6,7], value = 10

<

Supongo que te gusta

Origin blog.csdn.net/2301_76848549/article/details/134905747
Recomendado
Clasificación