Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package G;
- import java.io.IOException;
- import java.util.Scanner;
- /**
- * IMPORTANT: O nome da classe deve ser "Main" para que a sua solução execute
- * Class name must be "Main" for your solution to execute El nombre de la clase
- * debe ser "Main" para que su solución ejecutar
- */
- public class Main {
- public static boolean contains(int v[], int size, int value) {
- for(int i=0; i<size; i++) {
- if(v[i] == value) return true;
- }
- return false;
- }
- public static void main(String[] args) throws IOException {
- Scanner s = new Scanner(System.in);
- int t = s.nextInt();
- //
- int size = 0;
- int in[] = new int[11];
- int out[] = new int[11];
- //
- scope: for (int i = 0; i < t; i++) {
- //
- int n = s.nextInt();
- // Prepare first element
- int first = s.nextInt();
- if(first > 5) {
- System.out.println("Ho Ho Ho!");
- continue;
- }
- size = 2;
- in[0] = first;
- in[1] = -first;
- //
- for(int j=1; j<n; j++) {
- int current = s.nextInt();
- for(int k=0; k<size; k++)
- out[k] = in[k];
- int newSize = 0;
- for(int k=0; k<size; k++) {
- if(Math.abs(out[k] + current) <= 5 && !contains(in, newSize, out[k] + current))
- in[newSize++] = out[k] + current;
- if(Math.abs(out[k] - current) <= 5 && !contains(in, newSize, out[k] - current))
- in[newSize++] = out[k] - current;
- }
- if(newSize == 0) {
- System.out.println("Ho Ho Ho!");
- continue scope;
- }
- size = newSize;
- }
- System.out.println("Feliz Natal!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement