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 re(a, b, c, d) for (auto a = b; a <= c; a += d)
#define de(a, b, c, d) for (auto a = b; a >= c; a -= d)
#define ms (a); memset (a, 0, sizeof a);
#define imax INT_MAX
#define imin INT_MIN
#define wh(a) while (a --)
#define PII pair <int, int>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
template <typename T> bool chkmin (T &a, T b) {
return (b < a) ? a = b, 1 : 0;
}
template <typename T> bool chkmax (T &a, T b) {
return (b > a) ? a = b, 1 : 0;
}
using namespace std;
const int N = 1e6 + 5;
int T, n, k, c[N], d[N], f[N];
vector <PII> g[N];
signed main () {
cout << fixed << setprecision (0);
ios :: sync_with_stdio (0), cin.tie (0), cout.tie (0);
cin >> n >> k;
int a[n + 5][k + 5], b[n + 5][k + 5];
memset (a, 0, sizeof a);
memset (b, 0, sizeof b);
re (i, 1, n, 1) re (j, 1, k, 1) cin >> a[i][j], g[j].pb ({a[i][j], i});
re (i, 1, n, 1) re (j, 1, k, 1) cin >> b[i][j];
re (i, 1, k, 1)sort (g[i].begin(), g[i].end());
int res = 0;
while (1) {
int fl = 0;
re (i, 1, k, 1) {
while (1) {
if (c[i] >= n || f[i] < g[i][c[i]].F) break;
int h = g[i][c[i]].S;
d[h]++;
if (d[h] == k) {
re (j, 1, k, 1) f[j] += b[h][j];
fl = 1;
res++;
}
c[i]++;
}
}
if (! fl) break;
}
cout << res;
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... |