Question: Problem 4 Given are n real numbers a 1 , a 2 , . . . , an . Find a value t that can
Problem
Given are n real numbers a a an Find a value t that can be obtained by adding two
of these numbers and, moreover, the number of pairs of these numbers that add up to t is the
largest possible. Formally, find a t such that the size of the set i j i j ai aj t is
maximum among all possible ts For example, for we have:
This is the largest number of pairs that sum to the same number, and, therefore, t If
there are multiple possible ts find the smallest one. Give an On
log n algorithm for this
problem.
Problem
Input specification: The input consists of two lines. The first line contains a positive integer n The second line contains real numbers a a an separated by spaces. You may assume that the real numbers fit in double. You may also assume that n is at least and not larger than
Output specification: The output contains a single line with two numbers: the first is the largest number of pairs that sums to the same number, and the second is the number t ie the smallest sum with the largest number of corresponding pairs Output t with precision of six digits after the decimal point.
Sample input: input input input input input input input input
Sample output: answer answer answer answer answer answer answer answer
How to submit: Name your files FindMaxPairsDouble.java or FindMaxPairsDouble.cpp
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
