#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second
#define entire(x) (x).begin(), (x).end()
int32_t main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, k; cin >> n >> k;
vector<vector<int>> a(n, vector<int>(k, 0)), b(n, vector<int>(k, 0));
for (int i = 0; i < n; i++) for (int j = 0; j < k; j++) cin >> a[i][j];
for (int i = 0; i < n; i++) for (int j = 0; j < k; j++) cin >> b[i][j];
int ans = 0;
vector<int> cur(k, 0);
vector<bool> vis(n, false);
auto add = [&](){
for (int i = 0; i < n; i++){
if (vis[i]) continue;
bool ok = true;
for (int j = 0; j < k; j++) ok &= (a[i][j] <= cur[j]);
if (ok){
for (int j = 0; j < k; j++) cur[j] += b[i][j];
vis[i] = true; return true;
}
}
return false;
};
for (int i = 0; i < n; i++){
if (!add()) break;
ans++;
}
cout << ans << endl;
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... |