#P10204. Divine Wisdom

    ID: 12198 Type: Default 1000ms 256MiB

Divine Wisdom

Divine Wisdom

The knowledge of the god of wisdom, Bùyèl, is represented by an array \(a_0, a_1, \ldots, a_{N-1}\) (note that indices start at 0). Unfortunately, mortals cannot directly know the size \(N\) nor any of the elements \(a_i\) of this array.

The benevolent goddess Nashida reveals the following secrets:

  • For any \(0 \le i < N\), it holds that \(a_i \neq a_{(i+1)\bmod N}\).
  • There exists one and only one index \(i\) (with \(0 \le i a_{(i+1)\bmod N}\) and \(a_i > a_{(i+N-1)\bmod N}\).

You can ask questions to the divine. In each query, you supply an integer \(k\) (where \(0 \le k \le 10^9\)). Nashida will answer with the value \(a_{(d+k)\bmod N}\), where \(d\) is the index of the element returned in the previous query (with the initial value \(d=0\)). For example, if \(N=5\) and you query with \(1, 2, 3\) in sequence, the responses will be \(a_1, a_3, a_1\) respectively.

You have at most 333 queries. Your task is to determine and return the maximum element of the array \(a\).

Implementation Details:

You must implement the function buer with the following signature:

int buer(int T);

This function receives a test case number \(T\) and should return the maximum value found in the array \(a\) using the available query functions.

The following functions are provided by the interaction library. You must declare these functions in your code but do not implement them:

int ask(int k);    // returns a_{(d+k) mod N} and updates d accordingly
int cheat();       // returns N (using this function will penalize your score)

Note: You are not allowed to read from or write to any files or standard I/O streams aside from what is described. The sample main function provided below is for local testing only. In the final submission, only the function buer should be implemented (and the ask/cheat functions declared).

inputFormat

The input file consists of two lines. The first line contains two integers \(N\) and \(T\), representing the length of the array and the test case number respectively. The second line contains \(N\) positive integers \(a_0, a_1, \ldots, a_{N-1}\) representing the elements of the array.

outputFormat

Output a single line containing two integers: the total number of queries made and the maximum value found in the array.

sample

5 1
3 5 4 1 2
5 5

</p>