Submission #828852

#TimeUsernameProblemLanguageResultExecution timeMemory
828852t6twotwoTopical (NOI23_topical)C++17
40 / 100
1095 ms121332 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> f(n, m);
    queue<int> q;
    vector<multiset<pair<int, int>>> s(m);
    for (int i = 0; i < n; i++) {
        vector<int> a(m);
        for (int &x : a) {
            cin >> x;
        }
        if (a == vector(m, 0)) {
            q.push(i);
        } else {
            for (int j = 0; j < m; j++) {
                s[j].emplace(a[j], i);
            }
        }
    }
    vector u(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int &x : u[i]) {
            cin >> x;
        }
    }
    int ans = 0;
    vector<ll> t(m);
    while (!q.empty()) {
        int i = q.front();
        q.pop();
        ans++;
        for (int j = 0; j < m; j++) {
            t[j] += u[i][j];
            while (!s[j].empty() && (*s[j].begin()).first <= t[j]) {
                auto [_, k] = *s[j].begin();
                s[j].erase(s[j].begin());
                if (!--f[k]) {
                    q.push(k);
                }
            }
        }
    }
    cout << ans << "\n";
    return 6/22;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...