Part I The afternoon sun warms the faces of the weary knights in the tournament. The next round of challenges is scheduled to take place on the Memory Stack Desert, a flat surface of terrain which stretches out far into the horizon. Despite the late hour, it is still quite hot. Fortunately, the sun will soon set. The brave contestants arrive at a row of catapults. However, these are not the standard catapults used in other kingdoms. These machines have been engineered by the knightly Order, making them far more powerful! Each catapult consists of three segments stacked on top of one another. From bottom to top, they are labelled A, B, and C. Each segment can launch projectiles independently, making it possible to fire up to three projectiles simultaneously! Aiming such a catapult is also incredibly effective, as the projectiles are completely unaffected by the wind, flying steadily and at a constant speed according to the specified shooting power, which can be set independently for each segment using a dial on the side of the machine. Upon being launched, a projectile first travels diagonally upward at a 45-degree angle for as many segments as the set power allows. It then travels the same number of segments horizontally before descending diagonally downward, again at a 45-degree angle, until it reaches the ground. An example projectile path, launched from segment B with a shooting power of 5, looks like this: .................... ......↗→→→→→........ .....↗......↘....... ....↗........↘...... ...↗..........↘..... .C↗............↘.... .B..............↘... .A...............↘.. ==================== Another example projectile, launched from segment C with a shooting power of 3, is illustrated as follows: .................... .................... ....↗→→→............ ...↗....↘........... ..↗......↘.......... .C........↘......... .B.........↘........ .A..........↘....... ==================== Each knight has several targets in front of them (your notes), marked on the map with the letter T . The task is to destroy all the targets, with each projectile only destroying the first target it hits. It is also advisable to start from the top blocks of the target structure to prevent any unpredictable fall. For each shot, a ranking value can be calculated, which is the segment number (A:1, B:2, C:3) multiplied by the shooting power of the projectile. For the example shot above, the ranking value is: 2 (for segment B) * 5 (shooting power) = 10. You start to calculate from which segments and with what power the projectiles should be fired to destroy all the targets without wasting any shots. As your score, provide the sum of the rankings of all fired projectiles. Example based on the following notes: ............. .C........... .B......T.... .A......T.T.. ============= A projectile launched from segment C with a shooting power of 2: ...↗→→....... ..↗...↘...... .C.....↘..... .B......X.... .A......T.T.. ============= Ranking value: 3 * 2 = 6. A projectile launched from segment B with a shooting power of 2: ............. ...↗→→....... .C↗...↘...... .B.....↘..... .A......X.T.. ============= Ranking value: 2 * 2 = 4. A projectile launched from segment A with a shooting power of 3: ............. ....↗→→→..... .C.↗....↘.... .B↗......↘... .A........X.. ============= Ranking value: 1 * 3 = 3. The total ranking value for destroying all target blocks is 6 + 4 + 3 = 13 What is the ranking value of destroying your targets? Part II In the second round, the rules remain unchanged. However, the targets are now the ruins of a tower (your notes), which once served as an observation post for the desert. Since so little happens there, the structure has been abandoned and is now useless. Some of the ruin's blocks are made of Hard Rocks H , which require two projectiles to destroy. Example based on the following notes: ............. .C........... .B......H.... .A......T.H.. ============= The situation is almost the same as in the previous part, but some of the blocks (marked with H ) need two projectiles to destroy. The total ranking value for destroying all target blocks is (2 * 6) + 4 + (2 * 3) = 22 What is the ranking value of destroying all target blocks? Part III The sun has long set, and night has fallen. The stars twinkle pleasantly, but some of them seem to be... moving? They are also growing brighter and larger! Of course! They're not stars - it's a meteor shower! Fortunately, everything is heading towards the desert, so the people are safe. The catapult competition has been perfectly planned because the final round involves defending against moving targets. Has anyone ever tried shooting at falling meteors with a catapult? Luckily, all the meteors are traveling at a constant speed, identical to the catapult's projectiles, at an exact 45-degree angle to the ground, in the direction of the knights. Each projectile can destroy exactly one meteor, but all the knights will collaborate on executing a single plan, making it possible to fire multiple projectiles from the same segments simultaneously. The knights quickly note all current meteor coordinates relative to segment A (your notes), indicating that a sample space rock with coordinates 3 5 is 3 segments to the right of A and 5 segments above it: ............ ....#....... ............ ............ .C.......... .B.......... .A.......... ============ The knights mission is to devise a plan that will allow to shoot down the meteors as high in the air as possible without wasting any projectiles. If it is possible to shoot a meteor at the same altitude in more than one way, the one with the lower ranking score is chosen. Shooting power is always an integer value, and collisions can only occur at discrete points in time. Projectiles can be launched at any discrete time, not just at time 0. Example based on the following notes: 6 5 6 7 10 5 For the noted meteor positions, the initial situation looks like this: .......#...... .............. .......#...#.. .............. .............. .C............ .B............ .A............ ============== Let's start with the first meteor, which has initial coordinates 6 5 and moves as follows: .............. .............. .......#...... .............. .............. .C............ .B............ .A............ ============== time: 0 .............. .............. .......↙...... ......#....... .............. .C............ .B............ .A............ ============== time: 1 .............. .............. .......↙...... ......↙....... .....#........ .C............ .B............ .A............ ============== time: 2 .............. .............. .......↙...... ......↙....... .....↙........ .C..#......... .B............ .A............ ============== time: 3 .............. .............. .......↙...... ......↙....... .....↙........ .C..↙......... .B.#.......... .A............ ============== time: 4 If the knights decide to launch a projectile from segment C with a shooting power of 1 at time 0, it will hit the target at time 3: .............. .............. .......#...... .............. .............. .C............ .B............ .A............ ============== time: 0 .............. .............. .......↙...... ......#....... ..↗........... .C............ .B............ .A............ ============== time: 1 .............. .............. .......↙...... ......↙....... ..↗→.#........ .C............ .B............ .A............ ============== time: 2 .............. .............. .......↙...... ......↙....... ..↗→.↙........ .C..X......... .B............ .A............ ============== time: 3 However, launching a projectile from segment A with a shooting power of 2 at time 0 hits the target at the same altitude: .............. .............. .......#...... .............. .............. .C............ .B............ .A............ ============== time: 0 .............. .............. .......↙...... ......#....... .............. .C............ .B↗........... .A............ ============== time: 1 .............. .............. .......↙...... ......↙....... .....#........ .C.↗.......... .B↗........... .A............ ============== time: 2 .............. .............. .......↙...... ......↙....... .....↙........ .C.↗X......... .B↗........... .A............ ============== time: 3 The ranking score of that shoot is 2, which is lower compared to the use of segment C, so the knights will follow that option. The initial coordinates of the second meteor are 6 7 , and it moves as follows: .......#...... .............. .............. .............. .............. .C............ .B............ .A............ ============== time: 0 .......↙...... ......#....... .............. .............. .............. .C............ .B............ .A............ ============== time: 1 .......↙...... ......↙....... .....#........ .............. .............. .C............ .B............ .A............ ============== time: 2 .......↙...... ......↙....... .....↙........ ....#......... .............. .C............ .B............ .A............ ============== time: 3 .......↙...... ......↙....... .....↙........ ....↙......... ...#.......... .C............ .B............ .A............ ============== time: 4 It can be hit at altitude 4, by a projectile shot from segment B with a shooting power of 3, or from segment C with a shooting power of 2, both resulting with a ranking score of 6. The last meteor, which has initial coordinates 10 5 , is barely reachable, just above the ground, from segment C with a shooting power of 1, and this is the only way to destroy it. .............. .............. ...........#.. .............. .............. .C............ .B............ .A............ ============== time: 0 .............. .............. ...........↙.. ..........#... ..↗........... .C............ .B............ .A............ ============== time: 1 .............. .............. ...........↙.. ..........↙... ..↗→.....#.... .C............ .B............ .A............ ============== time: 2 .............. .............. ...........↙.. ..........↙... ..↗→.....↙.... .C..↘...#..... .B............ .A............ ============== time: 3 .............. .............. ...........↙.. ..........↙... ..↗→.....↙.... .C..↘...↙..... .B...↘.#...... .A............ ============== time: 4 .............. .............. ...........↙.. ..........↙... ..↗→.....↙.... .C..↘...↙..... .B...↘.↙...... .A....X....... ============== time: 5 The ranking score of that shoot is 3. The total ranking value is 2 + 6 + 3 = 11, and this is the best way to destroy all the meteors. Another example of when the launch of the projectile needs to be delayed: 5 5 For the noted meteor position, the initial situation looks like this: .............. .............. ......#....... .............. .............. .C............ .B............ .A............ ============== Shooting the projectile from segment A at time 0 would cause a collision at a non-discrete time, which is not allowed. The knights need to wait for the meteor to move 1 unit horizontally and vertically towards them: .............. .............. ......↙....... .....#........ .............. .C............ .B............ .A............ ============== time: 1 Then it is possible to launch the projectile from segment A with a power of 2 to destroy the meteor at a discrete time. The ranking value for this example is: 2. What is the lowest possible ranking score for the shots required to destroy all meteors at the highest altitudes possible?