sys.stdin.readline()
For Loop Consideration: Slow Input/Output Can Cause Time Limit Exceeded (TLE)
BAEKJOON BOJ #15552
Input_ The first line contains an integer T (maximum 1,000,000) representing the number of test cases. The next T lines each contain two integers A and B (1 ≤ A, B ≤ 1,000).
Output_ For each test case, print the sum of A + B on a new line in the order they appear.
Solution_
1
2
3
4
5
6
7
8
9
10
11
import sys
T = int(sys.stdin.readline().rstrip())
results = []
for _ in range(T):
A, B = map(int, sys.stdin.readline().split())
results.append(A + B)
sys.stdout.write("\n".join(map(str, results)) + "\n")
This post is licensed under CC BY 4.0 by the author.