#P15153. [SWERC 2024] Guess How the Ballet Will End

[SWERC 2024] Guess How the Ballet Will End

题目描述

In ancient Greek theater, the chorus would often dance.

The dances were a pleasure to watch; all the dancers on stage executed the same movements at the same time, going across the theater, left to right or right to left. Of course, no dancer could ever go past the borders of the scene. So if the instructions would have made them fall off the scene, they would simply have carried out the move until they reached the border and then stayed there until the next move. For instance, if the move said 5 steps to the right but the dancer only had space for two steps, he/she would have taken those two steps and would then have waited on the border for the next move.

You are excavating a theater and have found extraordinarily well-preserved papyri detailing the sequence of moves the dancers would make during many theater plays, a real treasure trove. The initial positions of the dancers is not known to you, since you have only found the papyri with the moves, and the rest of the instructions and the plays have been lost.

The instructions are a sequence of numbers, telling all the dancers to dance 3 steps to the left, 5 steps to the right, etc., all carrying out the same move at the same time. Adding a coordinate system to the scene, each dancer ii starts at the position (Xi,i)(X_i, i) and a move only impacts their XX coordinate (each dancer dances on his/her own line), so they cannot bump into each other. They also all move at the same speed; moving by nn steps means the same change of XX coordinate for all dancers, unless they hit the borders as explained above.

You have figured out that in some cases, because some dancers may need to cut some movements short due to the borders, it may happen that they will all end up in a perfect line (all at the same XX position) at the end of the dance. There are so many papyri that you have decided to write a program to find out if this is the case. Maybe you will learn interesting things about Greek dancing, depending on the number of plays where all the dancers end up all aligned.

Of course, you don't know the starting positions of the dancers, nor their number (only that they were at least a dozen), but you think there are some cases where your program will be able to tell for sure that the dancers end up all aligned and if so, where.

输入格式

On the first two lines of the input:

  • RR, an integer, the length of the scene. The valid XX positions of the dancers range from 00 (left of the scene) to RR (right of the scene). Going beyond that would make the dancers fall off the scene.
  • NN, the number of movements the dancers shall carry out.

On the third line, NN integers did_i, separated by spaces, the signed lengths of the moves the dancers shall carry out (a positive number means the dancer is moving to the right, a negative number that he/she is moving to the left).

输出格式

If you can be sure that all the dancers will end up being aligned at the same XX position, a single integer, corresponding to the position (distance from the left of the scene) where all the dancers will end up at the end of the moves.

Otherwise, output the string uncertain.

100
2
110 -20
80
100
1
50
uncertain
100
8
50 30 -40 10 -30 -50 30 -10
20

提示

Limits

  • 1R10,000,000,0001 \leq R \leq 10,000,000,000
  • 1N10001 \leq N \leq 1000
  • 10,000,000,000di10,000,000,000-10,000,000,000 \leq d_i \leq 10,000,000,000