Maximum of a Section X99803


Statement
 

pdf   zip

Given a sequence of integers, we specify a “section” of it using two different integers, say, a and b. The section is the part of the sequence that starts immediately after the first occurrence of a, if any, and ends immediately before the first occurrence of b after the first occurrence of a, if any.

For instance, given the sequence 6, 5, 1, 2, 1, 4, 3, 5, 4, 3, 5, 1 with a = 1 and b = 5 we specify the subsequence 2, 1, 4, 3 that starts just after the first 1 and ends just before the first 5 after that 1 (that is, the second 5).

Write a program that finds the maximum value of a specified section. In the case above, it would be 4.

Input

The input indicates first a and b, in one line, separated with whitespace; the subsequent line (or lines) constitute the sequence.

Output

If a does not appear in the sequence, or if it appears but b does not appear subsequently, your program must print “nonexistent section”; if they do appear but there are no intervening numbers, your program must print “empty section”; otherwise, your program must print “maximum is: ” followed by the corresponding maximum value.

Observation

Sections are exactly as in the related problem X66324 Identifying Sections, in case you have already attempted it. Some differences worthy of mention are that, there, from the input, we knew the length of the sequence beforehand, and we had several cases. Those two aspects change here, as does the handling of empty sections.

Public test cases
  • Input

    1 5
    6 0 1 2 1 4 3 5 4 3 5 1
    

    Output

    maximum is: 4
    
  • Input

    7 5
    6 0 1 2 1 4 3 5 4 3 5 1
    

    Output

    nonexistent section
    
  • Input

    5 7
    6 0 1 2 1 4 3 5 4 3 5 1
    

    Output

    nonexistent section
    
  • Input

    2 1
    6 0 1 2 1 4 3 5 4 3 5 1
    

    Output

    empty section
    
  • Input

    6 7
    6 8 1 2 1 4 3 5 4 3 5 7
    

    Output

    maximum is: 8
    
  • Information
    Author
    José Luis Balcázar
    Language
    English
    Translator
    José Luis Balcázar
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++ Python
    User solutions
    C++ Python