#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,k;
cin >> n >> k;
vector<vector<int>> r(n,vector<int>(k));
for(int i = 0;i < n;i++){
for(int j = 0;j < k;j++){
cin >> r[i][j];
}
}
vector<vector<int>> u(n,vector<int>(k));
for(int i = 0;i < n;i++){
for(int j = 0;j < k;j++){
cin >> u[i][j];
}
}
vector<int> po(k,0);
vector<vector<int>> si(k);
for(int i = 0;i < k;i++){
vector<int> ind(n);
iota(ind.begin(),ind.end(),0);
sort(ind.begin(),ind.end(),[&](int p1,int p2){
return r[p1][i] < r[p2][i];
});
si[i] = ind;
}
vector<i64> p(k);
vector<int> tot(n,k);
queue<int> q;
for(int i = 0;i < n;i++){
bool ok = true;
for(int j = 0;j < k;j++){
if(r[i][j] > 0){
ok = false;
break;
}
}
if(ok){
q.push(i);
tot[i] = 0;
}
}
int ans = 0;
while(!q.empty()){
int ro = q.front();
assert(tot[ro] <= 0);
q.pop();
ans ++;
for(int j = 0;j < k;j++){
p[j] += u[ro][j];
}
for(int j = 0;j < k;j++){
int ind = po[j];
while(ind < n && p[j] >= (i64) r[si[j][ind]][j]){
tot[si[j][ind]] --;
if(tot[si[j][ind]] == 0){
q.push(si[j][ind]);
}
ind ++;
}
po[j] = ind;
}
}
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... |