This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define endl '\n'
using namespace std;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
vector<vector<int>> req(n, vector<int>(k + 5, 0)), gain(n + 5, vector<int>(k + 5, 0));
vector<vector<pair<int, int>>> sortedreq(k + 5, vector<pair<int, int>>());
vector<int> count(n + 5, 0), cur(k + 5, 0), track(k + 5, 0);
for (int i = 0; i < n; i++){
for (int j = 0; j < k; j++){
cin >> req[i][j];
sortedreq[j].push_back({req[i][j], i});
}
}
for (int i = 0; i < n; i++){
for (int j = 0; j < k; j++){
cin >> gain[i][j];
}
}
for (int j = 0; j < k; j++){
sort(sortedreq[j].begin(), sortedreq[j].end());
}
int ans = 0;
while(true){
int change = 0;
for (int j = 0; j < k; j++){
while(track[j] < n && cur[j] >= sortedreq[j][track[j]].fi){
change = 1;
int module = sortedreq[j][track[j]].se;
count[module]++;
if (count[module] == k){
ans++;
for (int _ = 0; _ < k; _++){
cur[_] += gain[module][_];
}
}
track[j]++;
}
}
if (change == 0) break;
}
cout << ans;
}
# | 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... |