#K41712. Conveyor Belt Package Positions Simulation

    ID: 26927 Type: Default 1000ms 256MiB

Conveyor Belt Package Positions Simulation

Conveyor Belt Package Positions Simulation

In this problem, you are required to simulate a conveyor belt system that processes packages. The system consists of ( n ) segments, each with its own weight threshold. Every package starts at position zero. For each conveyor segment, the package moves one unit to the left (i.e. ( -1 )) if its weight is less than or equal to the threshold of that segment; otherwise, it moves one unit to the right (i.e. ( +1 )). The final position of a package is the sum of the movements over all ( n ) segments. Note that if there are no segments, the package remains at position zero. Your task is to compute and output the final positions of all packages after they pass through the entire conveyor belt.

inputFormat

The input is read from standard input (stdin) in the following format:

  • The first line contains an integer ( n ) representing the number of conveyor belt segments.
  • The second line contains ( n ) space-separated integers representing the thresholds for each segment. (If ( n = 0 ), this line will be empty.)
  • The third line contains an integer ( m ) representing the number of packages.
  • The fourth line contains ( m ) space-separated integers representing the weights of the packages. (If ( m = 0 ), this line will be empty.)

outputFormat

Output to standard output (stdout) a single line containing ( m ) space-separated integers. Each integer is the final position of the corresponding package after processing through the conveyor belt.## sample

3
5 3 4
4
6 2 5 1
3 -3 1 -3

</p>