We need to write a program that reads multiple datasets until "0 0". For each dataset, we have n (number of students) and m (number of subjects). Then m lines, each with n integers (scores for that subject). We need to compute the sum per student (across m subjects) and output the maximum sum.
Constraints: n up to 1000, m up to 50, number of datasets up to 100. This is straightforward: we can read the input and maintain an array of totals for n students, initialized to zero. For each subject line, we add each score to the corresponding student total. Then find the max.
Potential pitfalls: Input format: there might be extra whitespace, but reading with typical C++ or Python input parsing will handle it. Must stop at 0 0. Output each result on its own line.
We'll write a solution in Python for ease.
Implementation details:
- Use sys.stdin.read() or iterate lines.
- We'll parse tokens. Since datasets can be large (max 100 datasets, each with up to 1000*50 = 50000 numbers, total 5 million numbers, which is fine for Python.
- We'll read all ints from sys.stdin, then process sequentially.
Alternatively, read line by line.
Plan:
Initialize list of ints from sys.stdin. Use iterator.
Pseudo:
def solve():
import sys
data = list(map(int, sys.stdin.read().split()))
it = iter(data)
out = []
while True:
n = next(it); m = next(it)
if n == 0 and m == 0: break
totals = [0]*n
for _ in range(m):
for i in range(n):
totals[i] += next(it)
out.append(str(max(totals)))
sys.stdout.write("\n".join(out))
We must be careful: the input lines could be splitted arbitrarily; our token-based reading handles that.
Edge cases: all scores zero -> max zero. n=1 works.
Complexities: O(m*n) per dataset.
We'll output as required.
But note: There is sample input:
5 2
10 20 30 40 50
15 25 35 45 55
6 3
10 20 30 15 25 35
21 34 11 52 20 18
31 15 42 10 21 19
4 2
0 0 0 0
0 0 0 0
0 0
Our code should produce:
105
83
0
Yes.
Now, the problem description: "Scores of Final Examination" etc. So we just need to implement.
But there's a subtlety: The input includes lines that have n scores for each subject. They might be separated by spaces. Our token-based reading will work.
Thus the solution is straightforward.
However, we should note that the dataset count is up to 100, m up to 50, n up to 1000, so totals length up to 1000. That's fine.
We'll produce final code.
I'll now write the solution in a proper format with a solve() function.
Also ensure we handle StopIteration? But because the input ends with 0 0, it should be fine.
We can also implement line-by-line reading:
while True:
line = sys.stdin.readline()
if not line: break
n,m = map(int,line.split())
if n==0 and m==0: break
totals = [0]*n
for _ in range(m):
scores = list(map(int, sys.stdin.readline().split()))
# possibly check length? But should be n.
for i in range(n):
totals[i] += scores[i]
out.append(str(max(totals)))
That also works but requires reading lines. Since there might be multiple spaces, it's fine.
Both are acceptable.
But sometimes, the input lines may be broken across lines? Usually not. But the token approach is safer.
I'll go with token approach.
Now, write final answer.
Also, mention complexity and approach in comments.
I'm ready. ```python
import sys
def solve() -> None:
data = list(map(int, sys.stdin.read().split()))
it = iter(data)
out_lines = []
while True:
n = next(it, None)
m = next(it, None)
if n is None or m is None: # should not happen for valid input
break
if n == 0 and m == 0:
break
# totals[i] will hold the sum for student i (0-indexed)
totals = [0] * n
# read m subject lines, each containing n scores
for _ in range(m):
for i in range(n):
totals[i] += next(it)
out_lines.append(str(max(totals)))
sys.stdout.write("\n".join(out_lines))
if name == "main":
solve()