// soab
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define nl '\n'
void io() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
const int maxn = 1e6 + 1;
int n, k, p[maxn] = {0};
int cnt = 0, st;
bool valid;
int sub1() {
return valid? 1 : 0;
}
int sub2(vector<vector<int>>& r, vector<vector<int>>& u) {
vector<bool> vis(maxn, 0);
queue<int> q;
for(int i = 1; i <= n; i++) {
bool temp = 1;
for(int j = 1; j <= k; j++) {
if(r[i][j] != 0) {
temp = 0;
break;
}
}
if(temp) q.push(i);
}
while(!q.empty()) {
int v = q.front();
vis[v] = 1;
q.pop();
for(int j = 1; j <= k; j++) {
p[j] += u[v][j];
}
for(int i = 1; i <= n; i++) {
bool add = 1;
for(int j = 1; j <= k; j++) {
if(r[i][j] > p[j]) {
add = 0;
break;
}
}
if(add && !vis[i]) q.push(i);
}
}
int ans = 0;
for(int i = 1; i <= n; i++) ans += vis[i];
return ans;
}
signed main() {
io();
cin >> n >> k;
vector<vector<int>> r(n + 1, vector<int>(k + 1));
vector<vector<int>> u(n + 1, vector<int>(k + 1));
// int r[n + 1][k + 1], u[n + 1][k + 1];
for(int i = 1; i <= n; i++) {
bool temp = 1;
for(int j = 1; j <= k; j++) {
cin >> r[i][j];
if(r[i][j] != 0) temp = 0;
}
valid = valid || temp;
}
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= k; j++) cin >> u[i][j];
}
if(!valid) return cout << 0, 0;
if(n == 1) {
cout << sub1();
} else {
if(!valid) return cout << 0, 0;
cout << sub2(r, u);
}
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... |