#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll n, k; cin >> n >> k;
vector<vector<vector<ll>>> a(n + 1, vector<vector<ll>>(2, vector<ll>(k + 1, 0)));
for (ll i = 1; i <= n; i++)
for (ll j = 1; j <= k; j++)
cin >> a[i][0][j];
for (ll i = 1; i <= n; i++)
for (ll j = 1; j <= k; j++)
cin >> a[i][1][j];
if (n == 1 || k == 1) {
sort(a.begin(), a.end());
vector<ll> p(k + 1, 0);
ll ans = 0;
for (ll i = 1; i <= n; i++) {
bool possible = true;
for (ll j = 1; j <= k; j++)
if (p[j] < a[i][0][j])
possible = false;
if (possible) {
ans++;
for (ll j = 1; j <= k; j++)
p[j] += a[i][1][j];
}
}
cout << ans;
return 0;
}
set<int> done;
bool flag = true;
vector<ll> p(k + 1, 0);
ll ret = 0;
while (flag) {
int ans = 0;
for (int i = 1; i <= n; i++) {
if (done.count(i)) continue;
bool possible = true;
for (ll j = 1; j <= k; j++)
if (p[j] < a[i][0][j])
possible = false;
if (possible) {
ans++;
for (ll j = 1; j <= k; j++)
p[j] += a[i][1][j];
done.insert(i);
}
}
ret += ans;
if (ans == 0) flag = 0;
}
cout << ret;
}
# | 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... |