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
p
1,1
p
1,2
…
p
1,
n
p
2,1
p
2,2
…
p
2,
n
…
p
m
,1
p
m
,2
…
p
m,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.
p
j,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 ≤
p
j,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
s
k
of the student
k
is defined by
s
k
=
p
1,
k
+ … +
p
m,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

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>

template <typename T>
class matrix: public std::vector< std::vector<T> >
{
public:
	matrix(int m = 0, int n = 0, const T& v = T()):
		std::vector< std::vector<T> >(m, std::vector<T>(n, v)) {}
	int rows() const {return this->size();}
	int cols() const {return rows() == 0 ? 0 : this->at(0).size();}
};

template <typename T>
std::istream& operator>>(std::istream& is, matrix<T>& M)
{
	for (int i = 0; i < M.rows(); ++i)
		for (int j = 0; j < M.cols(); ++j)
			is >> M[i][j];
	return is;
}

int main()
{
	int m, n;
	while (std::cin >> n >> m && !(m == 0 && n == 0))
	{
		matrix<int> M(m, n);
		std::cin >> M;
		int maxs = 0;
		std::vector<int> s(n);
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < m; ++j)
				s[i] += M[j][i];
			if (maxs < s[i])
				maxs = s[i]; 
		}
		std::cout << maxs << '\n';
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3416
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
  while(true){
    int n, m;
    cin >> n >> m;
    if(!n) break;

    vector<int> total_score(n);

    for(int i=0;i<m;i++){
      for(int j=0;j<n;j++){
        int score;
        cin >> score;
        total_score[j] += score;
      }
    }
    sort(total_score.rbegin(), total_score.rend());

    cout << total_score[0] << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3448
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define int long long

int solve(){
	int n,m;
	cin>>n>>m;
	if(n+m==0){
		return 0;
	}
	vector<int> score(n,0);
	int a;
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			cin>>a;
			score.at(j)+=a;
		}
	}
	sort(score.begin(),score.end());
	cout<<score.at(n-1)<<endl;
	return 1;
}

#undef int
int main(){
	#define int long long
	while(solve()){}
}
accuracy: 1
time_ms: 10
memory_kb: 3380
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using int128 = __int128;
using State = string::const_iterator;
class ParseError {};
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define reps(i, l, r) for(ll i = (l); i < (r); i++)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl "\n";
const ll INF = LLONG_MAX / 4;
const ld inf = numeric_limits<long double>::max() / (ld)4;
const ll mod1 = 1000000007;
const ll mod2 = 998244353;
const ld pi = 3.1415926535897;
const ll Hash = (1ll << 61) - 1;
ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
ll dy[8] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T>
bool chmax(T &a, const T& b) {
	if (a < b) { a = b; return true; }
	return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
	if (a > b) { a = b; return true; }
	return false;
}
bool solve() {
	ll N, M; cin >> N >> M;
	if (N == 0 && M == 0) return false;
	vector<vector<ll>>P(M, vector<ll>(N));
	rep(i, M) rep(j, N) cin >> P[i][j];
	ll ans = 0;
	rep(i, N) {
		ll sum = 0;
		rep(j, M) {
			sum += P[j][i];
		}
		chmax(ans, sum);
	}
	cout << ans << endl;
	return true;
}
int main() {
	bool check = true;
	while (check) {
		check = solve();
	}
}
accuracy: 1
time_ms: 10
memory_kb: 3556
final_rank: 16

code_snippet: #include <bits/stdc++.h>
using namespace std;



int main(){
    for(int k=0;k<100;k++){
        int n=0,m=0;
        cin>>n>>m;

        vector<vector<int>> p(m,vector<int>(n));
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                cin>>p[i][j];
            }
        }

        if(!(1<=n and n<=1000)){
            return 0;
        }else if(!(1<=m and m<=50)){
            return 0;
        }else{
            for(int i=0;i<m;i++){
                for(int j=0;j<n;j++){
                    if(!(0<=p[i][j] and p[i][j]<=1000)){
                        return 0;
                    }
                }
            }

            vector<int> ans(n);
            for(int i=0;i<n;i++){
                for(int j=0;j<m;j++){
                    ans[i]+=p[j][i];
                }
            }

            sort(ans.begin(),ans.end());
            cout<<ans[n-1]<<endl;
        }
    }
    
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3712
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define erauni(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define vvec(vec,n,s) vector<vector<long long>> vec((ll)(n),vector<long long>((ll)(s)))
#define vvecstr(vec,n,s) vector<vector<string>> vec((ll)(n),vector<string>((ll)(s)))
#define vpush(vec,n) vec.push_back((ll)(n))
#define ll long long
#define INF (int)2e+9
#define co(ans) cout << ans << endl
#define cos(ans) cout << ans << " "
#define con cout << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
void solve(){
    int n,m;
    cin >> n >> m;
    
    if(n==0 && m == 0){
        exit(0);
    } 

    vector<int> vec(n);
    rep(i,m){
        rep(j,n){
            int p; cin >> p;
            vec[j] += p;

        }
    }
    int ans = 0;
    rep(i,n){
        ans = max(ans,vec[i]);
    }
    cout << ans << endl;
    
}

int main(){
    while(true){
        solve();
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3332
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) std::cerr << #x1 << ": " << x1 << std::endl
#define debug_2(x1, x2) std::cerr << #x1 << ": " << x1 << ", " << #x2 << ": " << x2 << std::endl
#define debug_3(x1, x2, x3) std::cerr << #x1 << ": " << x1 << ", " << #x2 << ": " << x2 << ", " << #x3 << ": " << x3 << std::endl
#define debug_4(x1, x2, x3, x4) std::cerr << #x1 << ": " << x1 << ", " << #x2 << ": " << x2 << ", " << #x3 << ": " << x3 << ", " << #x4 << ": " << x4 << std::endl
#define debug_5(x1, x2, x3, x4, x5) std::cerr << #x1 << ": " << x1 << ", " << #x2 << ": " << x2 << ", " << #x3 << ": " << x3 << ", " << #x4 << ": " << x4 << ", " << #x5 << ": " << x5 << std::endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~))(__VA_ARGS__)
#define debug_ary(a)                                                           \
    for (int i = 0; i < int(a.size()); i++) {                                  \
        std::cerr << #a << "[" << setw(2) << i << "]:" << (a)[i] << std::endl; \
    }
#define debug_sleep(a) sleep(a);
#define DBK std::cerr << "DBK" << std::endl;
#else
#define debug(...)
#define debug_ary(a)
#define debug_sleep(a)
#define DBK
#endif

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, a, n) for (int i = a; i < (int)(n); i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
template <class T>
constexpr T inf() { return ::numeric_limits<T>::max(); }
using ll = long long;
// max(int)=2*10^9
// max(long long)=9*10^18

int main() {
    while (true) {
        int n, m;
        cin >> n >> m;
        if (n == 0 && m == 0) break;
        ll ans = 0;
        vector<vector<int>> a(m, vector<int>(n));

        rep(i, m) {
            rep(j, n) {
                cin >> a[i][j];
            }
        }

        rep(i, n) {
            ll num = 0;
            rep(j, m) {
                // debug(j, i, a[j][i]);
                num += a[j][i];
            }
            // debug(ans, num);
            ans = max(ans, num);
        }
        cout << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3588
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const double pi = 3.141592653589793238;
const int INF = 2147483647;
const ll INFLL = 1LL << 62;
#define all(a) (a).begin(), (a).end()
#define allr(a) (a).rbegin(), (a).rend()
#define rep(i, r, n) for (int i = r; i < (int)n; i++)
#define pb push_back

void solve(int n, int m)
{
    int ans = 0;
    vector<int> a(n);
    rep(i, 0, m){
        rep(j, 0, n){
            int aa;
            cin >> aa;
            a[j] += aa;
        }
    }

    rep(i, 0, n){
        if(ans < a[i]) ans = a[i];

    }
    cout << ans << endl;
    return;
}

int main()
{
    int n, m;
    while (1)
    {
        cin >> n >> m;
        if (n == 0 && m == 0)
        {
            return 0;
        }
        solve(n, m);
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3584
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;

void solve() {
    int N, M;
    cin >> N >> M;
    if (N == 0 && M == 0) {
        exit(0);
    }
    vector<vector<int>> P(M, vector<int>(N));
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < N; j++) {
            cin >> P[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int sum = 0;
        for (int j = 0; j < M; j++) {
            sum += P[j][i];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
}

int main() {
    while (1) {
        solve();
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3532
final_rank: 15

code_snippet: #include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using ull = unsigned long long;

template <typename T>
bool ChMax(T& max, T val) {
	return (val > max) ? (max = val, true) : false;
}

bool Solve(void) {
	int n, m;
	cin >> n >> m;
	if (n == 0) return false;
	vector<int> sum(n);
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            int p;
            cin >> p;
            sum[j] += p;
        }
    }

    int max = 0;
    for (int i : sum) ChMax(max, i);

    cout << max << endl;

	return true;
}

int main(void) {
	while (Solve());
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3180
final_rank: 1

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n, m;
    while (cin >> n >> m) {
        if (n == 0 && m == 0) break;
        vector<int> ans(n, 0);
        vector<vector<int>> a(m, vector<int>(n));
        for(int i = 0; i < m; i++) {
            for(int j = 0; j < n; j++) {
                cin >> a[i][j];
                ans[j] += a[i][j];
            }
        }
        sort(ans.rbegin(), ans.rend());
        cout << ans[0] << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3528
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main(){
    vector<int> MAX(0);
    while(true){

    int n, m;
    

    cin >> n >> m;
    if(n == 0 && m == 0){
        break;
    }

    vector<vector<int>> score(m, vector<int>(n));
    vector<int> total(n, 0);
    for(int i=0; i<m; i++){
       
        for(int j=0; j<n; j++){
            cin >> score.at(i).at(j);
            
        }

    }

    for(int j=0; j<n; j++){
        for(int i=0; i<m; i++){
            total.at(j)+=score.at(i).at(j);
        }
    }
    
    sort(total.begin(), total.end());
    
    MAX.push_back(total.at(n-1));

    
    }
    for(int x=0; x<MAX.size(); x++){
        cout << MAX.at(x) << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3432
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int main() {
  vector<int> ans;
  while(true) {
    int n, m;
    cin >> n >> m;

    if (n == 0 && m == 0) break;

    vector<int> sum(n, 0);
    int score;
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < n; j++) {
        cin >> score;
        sum[j] += score;
      }
    }

    sort(sum.begin(), sum.end());
    ans.push_back(sum[sum.size()-1]);
  }

  rep(i, ans.size()) {
    cout << ans[i] << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3376
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m;

    while (true) {
        cin >> n >> m;
        if (n == 0 && m == 0) return 0;

        vector<int> score(n);
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                int p;
                cin >> p;
                score[j] += p;
            }
        }

        int maxSum = 0;
        for (int i = 0; i < n; i++) {
            maxSum = max(maxSum, score[i]);
        }

        cout << maxSum << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3448
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
    while (1)
    {
        int n,m,ans;
        cin >> n >> m;
        if(n==0&&m==0){
            break;
        }

        vector<int> po(n);
        rep(i,0,n){
            cin>> po.at(i);
        }
        rep(i,0,m-1){
            rep(j,0,n){
                int p;
                cin>>p;
                po.at(j)+=p;
            }
        }

        sort(po.begin(),po.end());
        ans=po.at(n-1);
        cout << ans << endl;
    
    }
    return (0);
}
accuracy: 1
time_ms: 10
memory_kb: 3360
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    while(true){
        int N, M;
        cin >> N >> M;
        if (N == 0 and M == 0) break;
        int Ans = -1;
        int Sum;
        vector<int> Score(N+1, 0);

        for (int i = 1; i <= M; i++) {
            for (int j = 1; j <= N; j++) {
                int Ten;
                cin >> Ten;
                Score.at(j) = Score.at(j) + Ten;
            }
        }

        for (int i = 1; i <= N; i++) Ans = max(Ans, Score.at(i));

        cout << Ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3364
final_rank: 6

code_snippet: #include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define REP(i,m,n) for(int i=m;i<=n;i++)
using namespace std;
using ll = long long;
int main(){
    rep(l,0,100){
        int n,m;
        cin>>n>>m;
        if(n==0&&m==0)return 0;
        vector<int> p(n,0);
        rep(i,0,m)rep(j,0,n){
            int temp;
            cin>>temp;
            p[j]+=temp;
        }
        int ans=*max_element(p.begin(),p.end());
        cout<<ans<<endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3360
final_rank: 4

code_snippet: #include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
  #include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
#endif
using namespace std;
using ll = long long;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define rep1(i,s,n) for (ll i = s; i < n; i++)
int main() {
    while(1){
      ll n,m;
      cin >> n >> m;
      if(n==0&&m==0){
        break;
      }
      vector<vector<ll>> p(m,vector<ll>(n));
      ll ans=0,check=0;
      rep(i,m){
        rep(j,n){
          cin >> p.at(i).at(j);
        }
      }
      rep(i,n){
        rep(j,m){
          check+=p.at(j).at(i);
        }
        ans=max(ans,check);
        check=0;
      }
      cout << ans << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3328
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main(){
    int n,m;
    vector<int> result;
    while(true){
        cin >> n >> m;
        if(n==0 && m==0){break;}
        vector<vector<int>> data(m,vector<int>(n));
        for(int i=0;i<m;i++){
            for(int &x:data.at(i)){
                cin >> x;
            }
        }
        int k = 0;
        for(int i=0;i<n;i++){
            int A = 0;
            for(int j=0;j<m;j++){
                A = A + data.at(j).at(i);
            }
            k = max(k,A);
        }
        result.push_back(k);
    }
    for(int x:result){
        cout << x << endl;
    }   
}
accuracy: 1
time_ms: 10
memory_kb: 3584
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define fr(i,n) for(int i=0; i<(n); i++)

int main() {
    vector<int> ans;
    while(true){
        int n,m,mx=0;
        cin >> n >> m;
        if(n==0&m==0) break;

        vector<vector<int>> v(m,vector<int> (n));
        fr(i,m){
            fr(j,n){
                cin >> v[i][j];
            }
        }
        fr(i,n){
            int tmp=0;
            fr(j,m){
                tmp += v[j][i];
            }
            mx = max(mx,tmp);
        }
        ans.push_back(mx);
    }
    fr(i,ans.size()) cout << ans[i] << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3432
final_rank: 10