#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define rep0(i, n) L(i, 0, n - 1)
#define rep1(i, n) L(i, 1, n)
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int n, k; cin >> n >> k;
vector<vector<i64>> r(n, vector<i64>(k)), u(n, vector<i64>(k));
rep0(i, n) rep0(j, k) cin >> r[i][j];
rep0(i, n) rep0(j, k) cin >> u[i][j];
vector<int> ord(n);
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int i, int j){
rep0(p, k) if(r[i][p] != r[j][p]) return r[i][p] < r[j][p];
return true;
});
vector<i64> sum(k);
vector<bool> vis(n);
int ans = 0;
rep1(loop, n){
// cout << "loop " << loop << '\n';
for (auto & i : ord) {
if (vis[i]) continue;
// cout << "try : " << i + 1 << '\n';
bool ok = true;
rep0(j, k) if (r[i][j] > sum[j]) ok = false;
if (ok) {
// cout << "eat : " << i + 1 << '\n';
vis[i] = true;
rep0(j, k) sum[j] += u[i][j];
// rep0(j, k) cout << sum[j] << " \n"[j == k - 1];
ans++;
}
}
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
114 ms |
31616 KB |
Output is correct |
5 |
Correct |
116 ms |
31608 KB |
Output is correct |
6 |
Correct |
121 ms |
31684 KB |
Output is correct |
7 |
Correct |
88 ms |
31684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
736 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Runtime error |
2 ms |
980 KB |
Execution killed with signal 11 |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
4 ms |
2908 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
604 KB |
Output is correct |
4 |
Correct |
114 ms |
31616 KB |
Output is correct |
5 |
Correct |
116 ms |
31608 KB |
Output is correct |
6 |
Correct |
121 ms |
31684 KB |
Output is correct |
7 |
Correct |
88 ms |
31684 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
736 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Runtime error |
2 ms |
980 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |