#include <bits/stdc++.h>
using namespace std;
using ll = long long;
main() {
cin.tie(0)->sync_with_stdio(0);
int n, k;
cin >> n >> k;
vector gain(n, vector<ll>(k));
vector todo(k, vector<pair<ll, int>>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
ll x; cin >> x;
todo[j][i] = {x, i};
}
}
for (int i = 0; i < k; i++) {
sort(todo[i].rbegin(), todo[i].rend());
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
cin >> gain[i][j];
}
}
int ans = 0;
queue<int> q;
vector<ll> rem(n, k), skill(k, 0);
auto upd = [&] (int i) {
while (todo[i].size() && todo[i].back().first <= skill[i]) {
int module = todo[i].back().second;
if (--rem[module] == 0) {
q.push(module);
}
todo[i].pop_back();
}
};
for (int i = 0; i < k; i++) upd(i);
while (q.size()) {
int i = q.front(); q.pop();
ans++;
for (int j = 0; j < k; j++) {
skill[j] += gain[i][j];
upd(j);
}
}
cout << ans << '\n';
}
Compilation message (stderr)
Main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
6 | main() {
| ^~~~
# | 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... |