#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
    int n, k, ans = 0; bool ok = true; cin >> n >> k;
    ii r[k][n]; int u[n][k], cnt[n], skill[k], ptr[k]; memset(skill, 0, sizeof(skill)); memset(ptr, 0, sizeof(ptr)); memset(cnt, 0, sizeof(cnt));
    for(int i = 0; i < n; i++) for(int j = 0; j < k; j++) {
        cin >> r[j][i].first;
        r[j][i].second = i;
    }
    for(int i = 0; i < n; i++) for(int j = 0; j < k; j++) cin >> u[i][j];
    for(int j = 0; j < k; j++) sort(r[j], r[j] + n);
    while(ok) {
        ok = false;
        for(int i = 0; i < k; i++) {
            while(ptr[i] != n && r[i][ptr[i]].first <= skill[i]) {
                cnt[r[i][ptr[i]].second]++;
                if(cnt[r[i][ptr[i]].second] == k) {
                    ans++;
                    for(int j = 0; j < k; j++) skill[j] += u[r[i][ptr[i]].second][j];
                }
                ptr[i]++; ok = true;
            }
        }
    }
    cout << ans;
}
| # | 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... |