A plus B

Points: 1
Time limit: 5.0s
Memory limit: 256M

Author:
Problem type
Allowed languages

This problem is intended as an introduction to the submission and judging system. For a detailed write-up of how to process input and output in your language of choice, see algocoding.wordpress.com/2015/04/23/fast-io-methods-for-competitive-programming/.

All input and output should be done using the standard input and output streams respectively.

Input Specification

The first line will contain an integer $$N$$ ($$1 \leq N \leq 10^5$$). The next $$N$$ lines will each contain a pair of space-separated integers whose absolute value is less than $$10^9$$.

Output Specification

Output $$N$$ lines each containing a single integer: The sum of each pair of integers from the input, in the same order as they are given.

Sample Input

2
1 1
-1 0

Sample Output

2
-1

• commented on Aug. 13, 2017, 7:53 p.m.

I spent far too long trying to cram this into one gross line.

for _ in range(int(input())): print(sum(map(int, input().split())))

Can anything think of something shorter? I feel like this could be much worse but I/O makes it hard to obfuscate.

• commented on Dec. 27, 2017, 8:13 a.m.

I suppose you could take advantage of the fact that Python functions are first-class objects:

for i in[input]*int(input()):print(sum(map(int,i().split())))
• commented on Jan. 1, 2018, 5:39 a.m.

Ha, that's fantastic! I knew you can overload std::function::operator() to create first-class functions, but I never really considered how Python functions are obviously first-class by definition.

• commented on Aug. 14, 2017, 5:23 a.m.

A couple of minutes in Haskell gets me this:

main=interact\$unlines.map(show.sum.(map read).words).tail.lines

Forgive the lack of whitespace. Readable Haskell would have between 4 and 16 extra spaces depending on your tastes.

• commented on Aug. 2, 2017, 10:45 p.m.

The time seems to vary quite a lot between runs. Something I posted took about a second, then I resubmitted the same code later and it took about 4 seconds..

• commented on Aug. 3, 2017, 6:57 a.m.

It is because you are using endl, which causes a buffer flush, and thus is variable.

• commented on July 27, 2017, 6:51 a.m.

I'm surprised at the difference between using

cout << endl

and

cout << '\n' then cout.flush() at the end of the program.

as well as the difference made with

ios::sync_with_stdio(false) and cin.tie(0).

I don't think there are any problems at all with only flushing cout at the end of your program, but are there any disadvantages when it comes to competitive programming when ios::sync_with_stdio(false) and cin.tie(0) would cause an error (other than when mixing C-style input/output and C++ streams)?

• commented on July 27, 2017, 7:08 a.m.

I am actually not surprised, this is a common issue with cin/cout. Using endl is very slow, as it forces a buffer flush. Using cin and cout can also be very slow unless you use the commands you posted, especially when the judge uses a HDD, which it does. Luckily, with the commands you mentioned, cin/cout become very fast. AFAIK it has no disadvantages other than that you can't use scanf/printf with cin/cout if you unsync and untie them.

• commented on July 27, 2017, 7:17 a.m.

Awesome, I'll make sure to use it in the future then. Thanks