PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000313. Sân khấu biểu diễn (Cow Dance Show)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Sân khấu biểu diễn (Cow Dance Show)

Cow Dance Show

Source: USACO

Version: Phuoc Hung OJ Extended

Problem Statement

The farm’s cows are preparing a dance show. The NN cows are numbered from 11 to NN in the order in which they must begin their routines. Cow ii performs for did_i units of time.

A stage of capacity KK allows at most KK cows to perform simultaneously. At time 00, cows 11 through KK begin. Whenever a cow finishes and leaves the stage, the next waiting cow in order immediately starts if any remain. Several cows may start simultaneously if several slots become free.

The show ends when the last cow finishes. Given a deadline TmaxT_{max}, find the smallest capacity KK that lets the show end no later than that deadline. Capacity K=NK=N is guaranteed to be feasible.

Input

  • The first line contains two integers N,TmaxN,T_{max}, the number of cows and the deadline.
  • Each of the next NN lines contains one integer did_i, the duration of cow ii’s routine.

Output

Print one integer, the minimum feasible stage capacity.

Subtasks

  • Subtask 1 (20 points): 1≤N≤201\le N\le20; 1≤Tmax≤1001\le T_{max}\le100; 1≤di≤301\le d_i\le30; max⁡di≤Tmax\max d_i\le T_{max}.
  • Subtask 2 (30 points): 1≤N≤1041\le N\le10^4; 1≤Tmax≤1061\le T_{max}\le10^6; 1≤di≤1051\le d_i\le10^5; max⁡di≤Tmax\max d_i\le T_{max}; d1=⋯=dNd_1=\cdots=d_N.
  • Subtask 3 (50 points): 1≤N≤1041\le N\le10^4; 1≤Tmax≤1061\le T_{max}\le10^6; 1≤di≤1051\le d_i\le10^5; max⁡di≤Tmax\max d_i\le T_{max}.

Examples

Input 1

5 8
4
7
8
6
4

Output 1

4

Explanation

With four slots, initial finish times are 4,7,8,6; cow 5 finishes at 8. With three slots cow 4 finishes at 10.