#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_multiset <int, null_type, less_equal <int>, rb_tree_tag, tree_order_statistics_node_update>
#define int long long
#define pvv pair <vector <int>, vector <int>>
#define double long double
#define pii pair <int, int>
#define tiii tuple <int, int, int>
#define tiiii tuple <int, int, int, int>
#define emb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define iShowSpeed cin.tie(NULL)->sync_with_stdio(false)
#define matrix vector <vector <int>>
#define mat(n, m) vector <vector <int>> (n, vector <int> (m));
const int mod = 1e9 + 7;
const int inf = 1e18;
const matrix II = {{1, 0}, {0, 1}};
int32_t main(){
iShowSpeed;
int n, k; cin >> n >> k;
vector <pvv> a(n + 1);
queue <pvv> cur;
int u[n + 1][k + 1], r[n + 1][k + 1];
memset(u, 0, sizeof u);
memset(r, 0, sizeof r);
for (int i = 1; i <= n; i++) {
a[i].first.emb(0);
for (int j = 1; j <= k; j++) {
a[i].first.emb(0);
cin >> a[i].first[j];
}
}
for (int i = 1; i <= n; i++) {
a[i].second.emb(0);
for (int j = 1; j <= k; j++) {
a[i].second.emb(0);
cin >> a[i].second[j];
}
}
sort(all(a));
for (int i = 1; i <= n; i++) {
cur.emplace(a[i].first, a[i].second);
}
int p[n + 1] = {0};
bool visited[n + 1] = {0};
int ans = 0;
while (1) {
queue <pvv> nxt;
bool yes = false;
while (!cur.empty()) {
auto [u, r] = cur.front(); cur.pop();
bool ok = true;
for (int j = 1; j <= k; j++) {
if (p[j] < u[j]) {
ok = false;
break;
}
}
if (!ok) {
nxt.emplace(u, r);
continue;
}
for (int j = 1; j <= k; j++) {
p[j] += r[j];
}
ans++;
yes = true;
}
cur = nxt;
if (!yes) 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... |