#include <bits/stdc++.h>
using namespace std;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,k;
cin >> n >> k;
int r[n][k];
int u[n][k];
pair<int,int>sortedreqs[k][n];
for(int i = 0;i<n;i++){
for(int j = 0;j<k;j++){
cin >> r[i][j];
sortedreqs[j][i]={r[i][j],i};
}
}
for(int i = 0;i<n;i++){
for(int j = 0;j<k;j++){
cin >> u[i][j];
}
}
for(int i = 0;i<k;i++){
sort(sortedreqs[i],sortedreqs[i]+n);
}
int cur[k];
int val[n];
fill(val,val+n,0);
fill(cur,cur+k,0);
int cn = 0;
int inds[k];
fill(inds,inds+k,0);
while(cn<n){
int curcn = 0;
for(int i = 0;i<k;i++){
bool fn=0;
while(inds[i]<n&&cur[i]>=sortedreqs[i][inds[i]].first){
val[sortedreqs[i][inds[i]].second]++;
assert(val[sortedreqs[i][inds[i]].second]<=k);
if(val[sortedreqs[i][inds[i]].second]==k){
fn=1;
int c = sortedreqs[i][inds[i]].second;
for(int i = 0;i<k;i++){
cur[i]+=u[c][i];
}
inds[i]++;
break;
}
inds[i]++;
}
if(fn){
curcn++;
break;
}
}
if(curcn){
cn+=curcn;
}
else{
break;
}
}
cout << cn;
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... |