Submission #1326293

#TimeUsernameProblemLanguageResultExecution timeMemory
1326293BolatuluTopical (NOI23_topical)C++20
0 / 100
6 ms1080 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define all(x) (x).begin(), (x).end()
// #define int ll

const int maxn = 1e6 + 7;

int n, k, cnt[maxn], p[maxn];
ll c[maxn];
vector<pair<int, int>> v[maxn];

void solve() {
    cin >> n >> k;
    int r[n + 1][k + 1], u[n + 1][k + 1];
    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];
    }

    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= n; j++) v[i].emplace_back(r[j][i], j);
        sort(all(v[i]));
    }

    int ans = 0;
    vector<int> t;
    while (ans < n) {
        for (int i = 1; i <= k; i++) {
            while (p[i] < n && v[i][p[i]].first <= c[i]) {
                int x = v[i][p[i]].second;
                cnt[x]++;
                if (cnt[x] == n) t.push_back(x);
                p[i]++;
            }
        }

        if (t.empty()) break;

        ans++;
        int x = t.back();
        for (int i = 1; i <= k; i++) {
            c[i] += u[x][i];
        }
        t.pop_back();
    }

    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int test = 1;
    // cin >> test;
    while (test--) {
        solve();
        // cout << '\n';
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...