IDENTIFICATION DIVISION.
PROGRAM-ID. 130B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP  PIC X(400).
01 N    PIC 9(3).
01 X    PIC 9(5).
01 CNT  PIC 9(5). 
01 Z    PIC 9(5).
01 ZO   PIC 9(5).
01 TBL.
   03 L PIC 9(3) OCCURS 100.
01 I    PIC 9(3).
01 P1   PIC 9(3).
01 P2   PIC 9(3). 
01 OUT  PIC ZZ9.
*>
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO N X.
*>
  ACCEPT INP.
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO L(I)
    COMPUTE P1 = P2 + 1
  END-PERFORM.  
*>
  MOVE 0 TO Z ZO CNT.
  PERFORM UNTIL (Z > X) OR (N < CNT)
    ADD 1 TO CNT
    COMPUTE Z = ZO + L(CNT)
    MOVE Z TO ZO
  END-PERFORM.  
*>
  MOVE CNT TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
*>
  STOP RUN.
