There are two programming questions in the drop down online written question. The first question is the general problem, the solution has many kinds, the second question has certain difficulty, the record is as follows: 1, the continuous most Yamato
Topic description
An array has n elements, and the largest and most contiguous array of children is obtained. For example: [ -1,2,1], and the largest contiguous array of children is [2,1], and the number is 3.
Input description
Enter two lines.
The first line, an integer n (1<=n<=100000), represents a total of n elements, a second act n, and each integer in the range of 32-bit int. separated by a space. Output description
All contiguous sub arrays and the largest values. Input example
3
-1 2 1 output examples
2
2. Restaurant
Topic description
A restaurant has n tables, each table has one parameter: A can accommodate the maximum number of guests, there are M group of customers, each group has two parameters: B number, C estimated consumption amount. In the case of not allowing the table, please implement an algorithm to select some of the guests, so that the total estimated consumption of the largest amount.
Input description
The input includes m+2 lines.
The first line consists of 2 integers n (1<=n<=50000), M (1<=m<=50000)
The second behavior n parameter a, the maximum number of people each table can accommodate, is separated by a space and is within the range of 32-bit int.
The next m line, two parameters B and c per line, representing the number of guests in the I group and the estimated consumption amount, separated by a space, in the range of 32-bit int. Output description
Outputs an integer that represents the maximum total estimated consumption amount. Input example
3 5
2 4 2
1 3
3 5
3 7
5 9
1 10 Output examples
20