#TP0000032. Tổng gần nhất (Closest Sums)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tổng gần nhất (Closest Sums)
Closest Sums
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
You are given integers and queries. For each query value , choose two elements at distinct positions whose sum is closest to , minimizing . Values may repeat, but the same position cannot be used twice.
For each query, the input guarantees that no two distinct sum values are tied for the minimum distance. Answer every query using the original array.
Input
- The first line contains , the number of integers.
- Each of the next lines contains exactly one integer .
- The following line contains , the number of queries.
- Each of the final lines contains exactly one query value .
Output
Print Case 1: on the first line. For each query in input order, print Closest sum to q is s., where is the sum of two elements at distinct positions closest to . Preserve capitalization, spaces, and the final period.
Subtasks
- Subtask 1 (20 points): ; ; for each array value; for every query; no distinct achievable sums tie in distance for any query.
- Subtask 2 (30 points): ; ; for each array value; for every query; no distinct achievable sums tie in distance for any query.
- Subtask 3 (50 points): ; ; for each array value; for every query; no distinct achievable sums tie in distance for any query.
Examples
Input
5
3
12
17
33
34
3
1
51
30
Output
Case 1:
Closest sum to 1 is 15.
Closest sum to 51 is 51.
Closest sum to 30 is 29.
Explanation
The array is . For query , the smallest achievable sum is , which is closest. For , choose for zero error. For , choose with error ; every other sum is farther away. The heading is Case 1: for this PHOJ input.