PDP-24 (2012) - Phase B' Junior High School (operators)

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 3.0s
Memory limit: 64M

Author:
Problem types
Allowed languages
C, C++, Java, Pascal, Python

Operational Amplifiers

Operational amplifiers are electronic devices that allow the execution of arithmetic operations between their input analog signals. A specific category of operational amplifiers is the adders, in which two input cables are connected, carrying two signals in the form of electric current measured as a positive or negative number. Another cable provides the output as the analog sum of their input signals, again in the form of electric current. The performance of these amplifiers is particularly high for input signals whose sum is close to 0. For example, good performance exists for two input signals that have approximately opposite values, such as 13 and -12. Operational amplifiers find extensive applications today, for instance, in mixing audio signals.

Problem

Develop a program in one of the IOI languages that takes as input N integers (positive and negative) in ascending order. The program should find the two numbers whose sum is closest to 0, directing the corresponding channels to the appropriate operational amplifier.

Input File

The input file named operators.in is a text file with the following structure: The first line contains the integer N\;(10 \le N \le 1.000.000), the number of integers. The second line contains exactly N integers, in ascending order, separated by spaces. For each such number X_i it will hold that -1.000.000.000 \le X_i \le 1.000.000.000, and additionally X_i \ne 0.

Output File

The output file named operators.out is a text file with the following structure: It has one line with exactly two integers separated by a space. These numbers are the two numbers from the operators.in file whose sum is closest to 0, first the smaller of the two and then the larger of the two.

Notes
  1. If there are more than one pair of numbers with the same optimal sum, choose any.
  2. The N numbers can all be positive or all negative.
  3. The two numbers in the output file must also be in ascending order.
Examples of Input - Output Files:
1st

STDIN (operators.in)

10
-101 -4 -1 6 95 1000 1001 1002 2000 9999

STDOUT (operators.out)

-4 6
2nd

STDIN (operators.in)

10
-110 -22 -1 28 35 105 140 145 200 300

STDOUT (operators.out)

-110 105

Maximum execution time: 3 sec.
Maximum available memory: 64 MB.

For 50% of the test cases, 10 \le N \le 1.000.


Comments

There are no comments at the moment.