#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k; cin >> n >> k;
vector<vector<int>> r(n + 1, vector<int>(k + 1));
vector<vector<int>> u(n + 1, vector<int>(k + 1));
map<int, set<pii>> list;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
cin >> r[i][j];
list[j].insert({r[i][j], i});
}
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= k; j++)
cin >> u[i][j];
map<int,int> cnt;
vector<int> curK(k + 1);
int res = 0;
while(true) {
bool found = false;
for (int i = 1; i <= k; i++) {
while(!list[i].empty()) {
auto it = list[i].begin();
int tax = it->first, pos = it->second;
if(tax > curK[i]) break;
cnt[pos]++;
list[i].erase(it);
if(cnt[pos] == k) {
for (int j = 1; j <= k; j++)
curK[j] += u[pos][j];
found = true;
res++;
}
}
}
if(!found) break;
}
cout << res << '\n';
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... |