| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1329159 | thanhson | Topical (NOI23_topical) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
using namespace std;
mt19937_64 rng(time(NULL));
ll rand(ll l, ll r) {
return rng() % (r - l + 1) + l;
}
ll power(ll a, ll b) {
if (b == 0) return 1;
ll ans = power(a, b / 2);
ans *= ans;
if (b % 2 == 1) ans *= a;
return ans;
}
const ll N = 1e3 + 5;
ll n, k, p[N], r[N][N], u[N][N], cnt[N];
void solve() {
cin >> n >> k;
for (int i = 1; i <= k; i ++) p[i] = 0;
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= k; j ++) {
cin >> r[i][j];
}
}
for (int i = 1; i <= n; i ++) {
for (int j = 1; j =< k; j ++) {
cin >> u[i][j];
}
}
if (n == 1) {
bool ok = true;
for (int i = 1; i <= k; i ++) {
if (r[1][j] != 0) {
ok = false;
break;
}
}
if (ok == true) {cout << 1; return;}
cout << 0; return;
}
ll t = 0;
bool nig = true;
while (nig == true) {
nig = false;
for (int i = 1; i <= n; i ++) if (cnt[i] == 0) {
bool ok = true;
for (int j = 1; j <= k; j ++) {
if (p[j] < r[i][j]) {
ok = false;
break;
}
}
if (ok == true) {
for (int j = 1; j <= k; j ++) {
p[j] += u[i][j];
}
t ++;
cnt[i] ++;
nig = true;
}
}
}
cout << t;
}
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
ll query = 1;
// cin >> query;
while (query --) solve();
}
