#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<vector<int>> r(n + 1, vector<int> (k + 1, 0));
    vector<vector<int>> v(n + 1, vector<int> (k + 1, 0));
    vector<int> p(k + 1, 0);
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= k; ++j){
            cin >> r[i][j];
        }
    }
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= k; ++j){
            cin >> v[i][j];
        }
    }
    int ans = 0;
    while(1){
        bool found_any  = 0;
        for(int i = 1; i <= n; ++i){
            int ok = 0;
            for(int j = 1; j <= k; ++j){
                if(r[i][j] == -1) break;
                if(p[j] >= r[i][j]) ok += 1;
            }
            if(ok == k){
                for(int j = 1; j <= k; ++j){
                    p[j] += v[i][j];
                    r[i][j] = -1;
                }
                ans += 1;
                found_any = 1;
            }
        }
        if(!found_any) break;
    }
    cout << ans << "\n";
    return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |