Submission #1327967

#TimeUsernameProblemLanguageResultExecution timeMemory
1327967Canuc80kTopical (NOI23_topical)C++20
100 / 100
338 ms70728 KiB
// im copy code (but i know how to AC)
// just to test stack for this prolem for my students 

#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);
    stack<int> q;
    vector<vector<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_back(a[j], i);
            }
        }
    }
    for (int i = 0; i < m; i++) {
        sort(s[i].begin(), s[i].end());
    }
    vector u(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int &x : u[i]) {
            cin >> x;
        }
    }
    int ans = 0;
    vector<int> p(m);
    vector<ll> t(m);
    while (!q.empty()) {
        int i = q.top();
        q.pop();
        ans++;
        for (int j = 0; j < m; j++) {
            t[j] += u[i][j];
            while (p[j] < s[j].size() && s[j][p[j]].first <= t[j]) {
                auto [_, k] = s[j][p[j]++];
                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...