PDP-26 (2014) - Phase C' - 1 (sumpair)

View as PDF

Submit solution

Points: 25 (partial)
Time limit: 2.0s
Memory limit: 16M

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

Sum of Pairs

A sequence of N integers is given. We want to be able to answer the question "Is there a pair of terms in the sequence whose sum equals X?" for any integer X.

Problem

Write a program in one of the IOI languages that reads the sequence of N numbers and then answers a series of such questions, for different values of X. If the answer is "yes", then your program should print the word "true"; otherwise, it should print the word "false".

Input Files:

The input files named sumpair.in are text files consisting of three lines: The first line contains two integers separated by a single space: the number N of sequence numbers (1 \le N \le 1.000.000) and the number Q of questions (1 \le Q \le 1.000). The second line contains N integers (the absolute value of which does not exceed 10^9 ), separated in pairs by a single space: the terms of the sequence. The third line contains Q integers separated in pairs by a single space: the questions to be answered.

Output Files:

The output files named sumpair.out are text files consisting of Q lines. The i-th line contains the answer to the i-th question: one of the words "true" or "false".

Example of Input - Output Files:

STDIN (sumpair.in)

12 5
2 42 5 -6 5 7 10 29 0 21 29 15
17 30 42 -4 58

STDOUT (sumpair.out)

true    // 2+15 = 7+10 = 17
false   // it does not result in 30
true    // 42+0 = 42
true    // 2+(-6) = -4
true    // 29+29 = 58

Formatting: In the output, each line terminates with a newline character.
Maximum execution time: 2 sec.
Maximum available memory: 16 MB.


Comments

There are no comments at the moment.