#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
ll r[n+1][k+1], u[n+1][k+1];
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= k; ++j) cin >> r[i][j];
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= k; ++j) cin >> u[i][j];
}
ll c[k+1];
fill(c+1, c+k+1, 0);
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq[k+1];
for (int i = 1; i <= n; ++i) pq[k].push({r[i][k], i});
int ans = 0;
while (1) {
for (int i = k; i >= 1; --i) {
while (!pq[i].empty() && pq[i].top().first <= c[i]) {
int j = pq[i].top().second;
pq[i].pop();
pq[i-1].push({r[j][i-1], j});
}
}
if (pq[0].empty()) break;
while (!pq[0].empty()) {
int j = pq[0].top().second;
pq[0].pop();
for (int i = 1; i <= k; ++i) c[i] += u[j][i];
ans++;
}
}
cout << ans << '\n';
}
# | 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... |