Programming contests

DEIK Regionális Programozó Csapatverseny, egyetemi kategória, 2024. december 1.

December 1, 2024, 10:00 AM – December 1, 2024, 3:00 PM

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 (xii=1Nx_{i} \ \ i=1\ldots N) as follows: for each soldier (xix_{i}​), he assigns as a superior the closest, more experienced soldier among those located either in the negative or positive direction (did_{i}​).

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 specification

The first line contains the number of soldiers, NN. The second line lists the soldiers’ experience points, xii=1,,Nx_{i}\ \ i=1,\ldots,N, separated by spaces. The third line contains the directions, di{,+}i=1,,Nd_{i}\in\{-,+\}\ \ i=1,\ldots,N, also separated by spaces.

Output specification

A single line containing the number of squads and the experience points of the strongest squad, separated by a space.

Constraints

1N100_0001\le N \le 100\_000
1xi100_0001\le x_{i} \le 100\_000

Sample input 1

  1. 8
  2. 8 6 4 3 9 2 5 7
  3. - + - + - + + +
download as text file

Sample output 1

  1. 3 22
download as text file

Sample input 2

  1. 11
  2. 10 8 6 4 3 9 2 5 7 5 9
  3. + - - + + - + - + + +
download as text file

Sample output 2

  1. 2 47
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024