Consider the following rules for a game, similar to those of a famous TV show: Six numbers are generated at random between 1 and 1000. A random number from 1 to is also generated. The goal is to get the number , or as close to it as possible. To do so, we may add, substract, multiply and divide the numbers of any non-empty subset of the six given numbers. No may be used more than once. Additionally, all intermediate results must be between 0 and . The divisions must be exact. Obviously, we cannot divide by zero.
Can you compute the result that is closest to ? For instance, if and we have the numbers , a possible solution (exact, in this case) is
Input consists of several cases, each with and .
For every case, print the result that is closest to . If there is a tie, choose the largest result.
Author: Salvador Roura
Event: Vint-i-quatrè Concurs de Programació de la UPC -
Semifinal
Date: 2026-06-18
Generation: 2026-06-10T19:44:06.672Z
© Jutge.org, 2006–2026.
https://jutge.org