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

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

Students and Mentors

면접 대비

메모리 제한1024 MB

요약
각 학생마다 자신의 평가의 두 배 이하이면서 다른 학생인 평가 중 가장 큰 값을 찾고, 없으면 -1을 출력한다.
난이도

보통10점 중 5점

유형
배열, 이분 탐색, 정렬, 그리디
정답자
아직 제출이 없습니다

문제

A group of N\mathbf{N} students prepares together for upcoming programming competitions such as Kick Start and Code Jam by Google. To help each other prepare, it was decided that each student will pick a mentor among other students. A mentor will help their mentee to solve problems, learn algorithms, track their progress, and will generally support them throughout preparation.

Each student will have exactly one mentor among all other students, and a person can be a mentor to multiple people. For every student ii we know their rating R_i\mathbf{R\_i} which approximates how good that student is at programming competitions. Because it is believed that a mentor should not be much stronger than their mentee, a student jj can be a mentor of student ii only if R_j≤2×R_i\mathbf{R\_j} \le 2 \times \mathbf{R\_i}. Note that a mentor can even have a rating that is lower or equal to their mentee's rating.

Unsurprisingly, each student wants to have the strongest possible mentor. For each student, can you help to figure out what is the highest possible rating of a mentor they can pick?

입력

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} test cases follow. Each test case consists of two lines.

The first line of each test case contains an integer N\mathbf{N}, representing the number of students in a group.

The second line of each test case contains N\mathbf{N} integers R_1 R_2 R_3 … R_N\mathbf{R\_1} \ \mathbf{R\_2} \ \mathbf{R\_3} \ \dots \ \mathbf{R\_N} where R_i\mathbf{R\_i} is a rating of the ii-th student.

출력

For each test case, output one line containing Case #x: M1 M2 M3 ... MN$ where xx is the test case number (starting from 1), and M_iM\_i is the maximum possible rating of the ii-th student's mentor or −1-1 if there are no suitable mentors for that student.

제한

  • 1≤T≤1001 \le \mathbf{T} \le 100.
  • 1≤R_i≤1061 \le \mathbf{R\_i} \le 10^6, for all ii.

예제1

  1. 예제 1

    입력
    3
    3
    2000 1500 1900
    5
    1000 600 1000 2300 1800
    2
    2500 1200
    
    예상 출력
    Case #1: 1900 2000 2000
    Case #2: 1800 1000 1800 1800 2300
    Case #3: 1200 -1