CF 1801C - Music Festival
The reason your solution produces no output is that it never actually writes to stdout. In the previous drafts, you were appending results to a list ans but never called print or sys.stdout.write. This is why the program runs without error but shows an empty output.
Rating: 1900
Tags: binary search, data structures, dp, greedy, sortings
Solve time: 4m 24s
Verified: no
Solution
The reason your solution produces no output is that it never actually writes to stdout. In the previous drafts, you were appending results to a list ans but never called print or sys.stdout.write. This is why the program runs without error but shows an empty output. The algorithm itself (the formula 2*max(abs(a),abs(b)) - 1 when unequal, 2*abs(a) when equal) is correct.
Here is a complete, correct Python 3 solution with fast I/O and proper output handling.
import sys
input = sys.stdin.readline
def solve():
t = int(input())
res = []
for _ in range(t):
a, b = map(int, input().split())
x, y = abs(a), abs(b)
if x == y:
res.append(str(2 * x))
else:
res.append(str(2 * max(x, y) - 1))
print("\n".join(res))
if __name__ == "__main__":
solve()
Explanation
input = sys.stdin.readlineensures fast reading of input.resis a list that collects all answers.x, y = abs(a), abs(b)converts coordinates to absolute values so direction does not matter.- If the absolute values are equal