아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Squary

메모리 제한1024 MB

요약
정수 목록이 주어질 때, 1개 이상 K개 이하의 정수를 더해 합의 제곱이 제곱의 합과 같아지도록 만들 수 있는지 판별하고 그 목록을 출력한다.
난이도

보통10점 중 6점

유형
수학, 그리디, 구현, 조합론
정답자
아직 제출이 없습니다

문제

Addition and squaring do not commute. That is, the square of the sum of all elements of a list of integers is not necessarily equal to the sum of the squares of those same elements. However, this is true for some lists; one example is \[3,−2,6]\[3,-2,6], because (3+(−2)+6)2=49=32+(−2)2+62(3+(-2)+6)^2=49=3^2+(-2)^2+6^2. Let us call these lists squary.

Given a (not necessarily squary) list of relatively small integers, we want to know whether it is possible to add at least 11 and at most KK more elements such that the final list is squary. Each added element must be an integer between −1018-10^{18} and 101810^{18}, inclusive, and these do not have to be distinct from each other or from the initial list's elements.

입력

The first line of the input gives the number of test cases, TT. TT test cases follow. Each test case is described in two lines. The first line contains two integers NN and KK, the number of elements of the initial list and the maximum number of elements you may add, respectively. The second line contains NN integers E_1,E_2,…,E_NE\_1,E\_2,…,E\_N, representing the NN elements of the initial list.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1). If it is possible to add at least 11 and at most KK elements (each an integer between −1018-10^{18} and 101810^{18}, inclusive) to the initial list such that the square of the sum of its elements equals the sum of the squares of its elements, yy should be z_1z\_1 z_2z\_2 …\dots z_rz\_r, where 1≤r≤K1≤r≤K and the z_iz\_i values are the additional elements. If there is no way to accomplish this, yy should be IMPOSSIBLE.

제한

  • 1≤T≤1001≤T≤100.
  • 1≤N≤10001≤N≤1000.
  • −1000≤E_i≤1000-1000≤E\_i≤1000, for all ii.

예제2

  1. 예제 1

    입력
    4
    2 1
    -2 6
    2 1
    -10 10
    1 1
    0
    3 1
    2 -2 2
    
    예상 출력
    Case #1: 3
    Case #2: IMPOSSIBLE
    Case #3: -1000000000000000000
    Case #4: 2
    
  2. 예제 2

    입력
    3
    3 10
    -2 3 6
    6 2
    -2 2 1 -2 4 -1
    1 12
    -5
    
    예상 출력
    Case #1: 0
    Case #2: -1 15
    Case #3: 1 1 1 1 1 1 1 1 1 1 1