#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<int(n);i++)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) for(int i=int(n)-1;i>=0;i--)
#define dforsn(i,s,n) for(int i=int(n)-1;i>=int(s);i--)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<int,int> ii;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n,k;
cin>>n>>k;
vector<vi> r(n,vi(k)),u(n,vi(k));
forn(i,n) forn(j,k) cin>>r[i][j];
forn(i,n) forn(j,k) cin>>u[i][j];
vector<vi> order(k,vi(n));
forn(i,k){
iota(all(order[i]),0);
sort(all(order[i]),[&](const int &lhs, const int &rhs){
return r[lhs][i]<r[rhs][i];
});
}
vi need(n,k);
vi j(k,0);
vll p(k,0);
queue<int> q;
int ans=0;
while(1){
forn(i,k){
while(j[i]<n&&p[i]>=r[order[i][j[i]]][i]){
int pos=order[i][j[i]];
if(!--need[pos]) q.push(pos);
j[i]++;
}
}
if(q.empty()) break;
while(!q.empty()){
int pos=q.front(); q.pop();
ans++;
forn(i,k) p[i]+=u[pos][i];
}
}
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... |