Problem:


Scores of Final Examination

I am a junior high school teacher.
The final examination has just finished, and I have
all the students' scores of all the subjects.
I want to know the highest total score among the students,
but it is not an easy task as the student scores are
listed separately for each subject.
I would like to ask you, an excellent programmer, to help me
by writing a program that finds the total score of a student
with the highest total score.

Input

The input consists of multiple datasets, each in the following format.

n m

p1,1 p1,2 &hellip; p1,n

p2,1 p2,2 &hellip; p2,n

&hellip;

pm,1 pm,2 &hellip; pm,n

The first line of a dataset has two integers n and m.
n is the number of students (1 ≤ n ≤ 1000).
m is the number of subjects (1 ≤ m ≤ 50).
Each of the following m lines gives n students' scores
of a subject.
pj,k is an integer representing
the k-th student's
score of the subject j (1 ≤ j ≤ m
and 1 ≤ k ≤ n).
It satisfies 0 ≤ pj,k ≤ 1000.

The end of the input is indicated by a line containing two zeros.
The number of datasets does not exceed 100.

Output

For each dataset, output the total score of a student with the highest
total score.
The total score sk
of the student k is defined by
sk =
p1,k + &hellip; + pm,k.

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

Output for the Sample Input

105
83
0



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


Sample output:
105
83
0

Submission status: Accepted

Solution code:
while (True):
    a, b = list(map(int, input().split(" ")))
    if(a == 0 and b == 0):
        break
    # print(a, b)
    score = [[0] for i in range(b)]
    for i in range(b):
        score[i] = list(map(int, input().split()))
    sum = 0
    maxSum = 0
    for i in range(a):
        sum = 0
        for j in range(b):
            sum += score[j][i]
            if (sum > maxSum):
                maxSum = sum
    print(maxSum)

Submission status: Accepted

Solution code:
def main():
    import sys
    from itertools import chain
    while True:
        n, m = map(int, sys.stdin.readline().split())
        if n == m == 0:
            break

        A = list(chain.from_iterable(map(int, sys.stdin.readline().split()) for _ in range(m)))
        ans = 0
        for i in range(n):
            sm = sum(A[i::n])
            if ans < sm:
                ans = sm
        print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#無限ループと標準入力両方0だったらおわる
while True:
    a,b = map(int,input().split())
    if a == 0 and b == 0:break
    kei = [0 for _ in range(a)]
    
    #標準入力をし入力値を合計する
    for i in range(b):
        line = list(map(int,input().split()))
        for j in range(0,a):
            kei[j] += line[j]
    
    #一番大きい数を出力する
    print(max(kei))

Submission status: Accepted

Solution code:
while True:
    n, m = map(int, input().split())
    if n == m == 0:
        break
    students = [0 for _ in range(n)]
    for _ in range(m):
        scores = list(map(int, input().split()))
        for i in range(n):
            students[i] += scores[i]
    print(max(students))

Submission status: Accepted

Solution code:
while True:
    n,m=map(int,input().split())
    if n==0 and m==0:
        break
    p=[list(map(int,input().split())) for i in range(m)]
    for i in range(1,m):
        for j in range(n):
            p[i][j]+=p[i-1][j]
    print(max(p[m-1]))

Submission status: Accepted

Solution code:
for i in range(110):
    x,y = map(int,input().split()) #xは生徒,yは科目
    if x == y == 0:
        break
    else:
        a = [0]*x
        for j in range(y):
            ls = list(map(int,input().split()))
            for _ in range(x):
                a[_] += ls[_]
        print(max(a))

Submission status: Accepted

Solution code:
scores = [[0] * 51 for i in range(1001)]

while(1):
    try:
        n,m = (int(x) for x in input().split())
        if n == 0:break
        for i in range(0,m):
            scores[i] = list(int(x) for x in input().split())
            
        maxSum = 0
        for i in range(0,n):
            sum = 0
            for j in range(0,m):
                sum += scores[j][i]
            maxSum = max(maxSum,sum)
        print(maxSum)
    except:
        break

Submission status: Accepted

Solution code:
while True:
	n,m=map(int,input().split())
	if n==m==0:
		break
	else:
		score=[0]*n
		for i in range(m):
			p=list(map(int,input().split()))
			for j in range(n):
				score[j]+=p[j]
		print(max(score))

Submission status: Accepted

Solution code:
while 1:
    n, m = map(int, input().split())
    if n == 0:
        break
    a = []
    for _ in range(m):
        a.append(list(map(int, input().split())))
    b = []
    for i in range(n):
        s = 0
        for j in range(m):
            s += a[j][i]
        b.append(s)
    print(max(b))

Submission status: Accepted

Solution code:
while True:
    n,m = map(int,input().split())
    if n == m == 0:
        break
    score = [0 for i in range(n)]
    for i in range(m):
        hokan = list(map(int,input().split()))
        for j in range(n):
            score[j] += hokan[j]
    score.sort(reverse = True)
    print(score[0])

Submission status: Accepted

Solution code:
while True:
    n, m = map(int,raw_input().split(' '))
    if n == 0:
        break
    scores = [0] * n
    for i in range(m):
        j = 0
        for s in map(int,raw_input().split(' ')):
            scores[j] += s
            j += 1
    print max(scores)

Submission status: Accepted

Solution code:
#!/usr/bin/python3

import array
from fractions import Fraction
import functools
import itertools
import math
import os
import sys


def main():
    while True:
        N, M = read_ints()
        if (N, M) == (0, 0):
            break
        P = [read_ints() for _ in range(M)]
        print(solve(N, M, P))


def solve(N, M, P):
    T = [[P[j][i] for j in range(M)] for i in range(N)]
    return max([sum(t) for t in T])


###############################################################################
# AUXILIARY FUNCTIONS

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
期末試験の成績
https://onlinejudge.u-aizu.ac.jp/challenges/sources/ICPC/Prelim/1632

"""
import sys


def solve(n, m):
    scores = [[int(x) for x in input().split()] for _ in range(m)]
    return max([sum(z) for z in zip(*scores)])


def main(args):
    while True:
        n, m = map(int, input().split())
        if n == 0 and m == 0:
            break
        ans = solve(n, m)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
while True :
    a = list(map(int,input().split()))
    if a[0] == 0:
        break
    else:
        max_sum = 0
        s = 0
        table = []
        for i in range(a[1]):
            table.append(list(map(int,input().split())))
        for i in range(a[0]):
            s = 0
            for j in range(a[1]):
                s += table[j][i]
            max_sum = max(s,max_sum)
        print(max_sum)

Submission status: Accepted

Solution code:
def main():
    n,k = map(int,input().split())
    if n * k == 0:
        return False
    ans = [0 for _ in range(n)]
    for _ in range(k):
        a = list(map(int,input().split()))
        for i in range(n):
            ans[i] += a[i]
    print(max(ans))
    return True

while main():
    pass

Submission status: Accepted

Solution code:
while True:
    n, m = map(int, input().split())
    if n+m==0 : break
    a = [list(map(int,input().split())) for i in range(m)]
    for i in range(1, m):
        for j in range(n):
            a[i][j] += a[i-1][j]
    print(max(a[m-1]))

Submission status: Accepted

Solution code:
import os,re,sys,operator
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy
import heapq

setrecursionlimit(10**6)
while 1:
    n,m=map(int,stdin.readline().rstrip().split())
    if (n,m)==(0,0):
        break
    a=[list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]
    print(max(sum(i) for i in zip(*a)))

Submission status: Accepted

Solution code:
while True:
    n,m = map(int, input().split())
    if(n+m  ==0):
        break
    li = list()
    for i in range(m):
        line = [num for num in map(int, input().split())]
        li.append(line)
    ans = [0 for i in range(n)]
    for i in range(m):
        for j in range(n):
            ans[j] += li[i][j]
    print(max(ans))

Submission status: Accepted

Solution code:
# coding=utf-8

###
### for python program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    def pnum_check(self, n):
        if (n==1):
            return False
        elif (n==2):
            return True
        else:
            for x in range(2,n):
                if(n % x==0):
                    return False
            return True

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
# print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
# print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
# print(" {}".format(i), end="")

def printA(A):
    N = len(A)
    for i, n in enumerate(A):
        print(n, end='')
        if i != N-1:
            print(' ', end='')
    print()

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート
# N = N.sort()

# 10000個の素数リスト
# P = mymath.pnum_eratosthenes(105000)

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

while True:
    N, M = [int(x) for x in input().split()]
    if N==0 and M==0:
        break
    P = []
    for i in range(M):
        P.append([int(x) for x in input().split()])

    A = []
    for i in range(N):
        temp = 0
        for j in range(M):
            temp += P[j][i]    
        A.append(temp)

    print(max(A))

Submission status: Accepted

Solution code:
while True:
    n=[int(e) for e in input().split()]

    if(n[0]==0)and(n[1]==0):
        break

    m=[[0 for i in range(n[0])] for j in range(n[1]+1)]
    
    for j in range(n[1]):
        m[j]=[int(e) for e in input().split()]

    for k in range(n[0]):
        score=0
        for j in range(n[1]):
            score=m[j][k]+score
        m[(n[1])][k]=score
    
    max_=m[(n[1])][0]
    for k in range(n[0]):
        if max_<m[(n[1])][k]:
            max_=m[(n[1])][k]

    print(max_)

Submission status: Accepted

Solution code:
while 1:
    N, M = map(int, input().split())
    if N == 0:
        break
    S = [list(map(int, input().split())) for i in range(M)]
    ans = 0
    for i in range(N):
        ans = max(ans, sum(S[j][i] for j in range(M)))
    print(ans)