|
|||
Squads
Peter is playing with his toy soldiers, lining them up side by side. He wants to form squads from them, where within each squad, everyone except the commander has a direct superior. He will use the experience points of the soldiers () as follows: for each soldier (), he assigns as a superior the closest, more experienced soldier among those located either in the negative or positive direction (). Of course, if no such soldier exists in the respective direction, no one is assigned as their superior. In this way, one or more squads are formed. The experience points of a squad are defined as the sum of the experience points of its members, which Péter also refers to as the squad’s strength.Examples: I. x: 8 6 4 3 9 2 5 7 d: - + - + - + + + squad experience 8 8 3,4,6,9 22 2,5,7 14 II. The soldiers' experience points are not necessarily unique! In such cases, the soldiers are referred to by their indices instead of their experience points. x: 10 8 6 4 3 9 2 5 7 5 9 d: + - - + + - + - + + + i: 1 2 3 4 5 6 7 8 9 10 11 squad experience 1,2,3,4,5,6,7,8 47 9,10,11 21 Input specificationThe first line contains the number of soldiers, . The second line lists the soldiers’ experience points, , separated by spaces. The third line contains the directions, , also separated by spaces. Output specificationA single line containing the number of squads and the experience points of the strongest squad, separated by a space. Constraints
Sample input 1
Sample output 1
Sample input 2
Sample output 2
|
|||
University of Debrecen; Faculty of Informatics; v. 09/30/2024 |