#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#define int long long
using namespace std;
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	int sol=0;
	cin>>n>>k;
	vector<priority_queue<pair<int,int> > >req(k);
	vector<vector<int> >gain(n, vector<int>(k));
	vector<int>p(k, 0);
	vector<int>ans(n, 0);
	for (int i=0; i<n; i++){
		for (int j=0; j<k; j++){
			int x; cin>>x;
			req[j].push(make_pair(-x, i));
		}
	}
	for (int i=0; i<n; i++){
		for (int j=0; j<k; j++) cin>>gain[i][j];
	}
	
	bool algo=true;
	while (algo==true){
		algo=false;
		for (int i=0; i<k; i++){
			while (!req[i].empty()){
				if (-req[i].top().first<=p[i]){
					int ind=req[i].top().second;
					req[i].pop();
					ans[ind]++;
					if (ans[ind]==k){
						ans[ind]=0;
						algo=true;
						sol++;
						for (int j=0; j<k; j++){
							p[j]+=gain[ind][j];
						}
					}
				}else break;
			}
		}
	}
	cout<<sol<<'\n';
}
| # | 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... |