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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<vector<int>> a, b;
vector<pair<int, int>> g[1000005];
long long int c[1000005], d[1000005], f[1000005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, k;
cin >> n >> k;
a = vector<vector<int>> (n + 1, vector<int>(k + 1, 0));
b = vector<vector<int>> (n + 1, vector<int>(k + 1, 0));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
cin >> a[i][j];
g[j].push_back({a[i][j], i});
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
cin >> b[i][j];
}
}
for (int i = 1; i <= k; i++) {
sort(g[i].begin(), g[i].end());
}
int res = 0;
while (1) {
int flag = 0;
for (int i = 1; i <= k; i++) {
while (c[i] < n && f[i] >= g[i][c[i]].first) {
int h = g[i][c[i]].second;
d[h]++;
if (d[h] == k) {
for (int j = 1; j <= k; j++) {
f[j] += b[h][j];
}
flag = 1;
res++;
}
c[i]++;
}
}
if (flag == 0) break;
}
cout << res;
}
# | 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... |