Submission #933138

#TimeUsernameProblemLanguageResultExecution timeMemory
933138browntoadTopical (NOI23_topical)C++14
100 / 100
432 ms132888 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define pii pair<int, int>
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#define f first
#define s second
#define pb push_back
#define IOS() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'

const ll maxn = 1e6+5;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;

int n, k;
vector<pii> nw[maxn];
vector<int> nwptr(maxn);

vector<int> val(maxn);
vector<int> sat(maxn); // how many topics satisfies for each module
vector<vector<int>> bonus;

signed main(){
    IOS();
    cin>>n>>k;

    REP(i, n){
        REP(j, k){
            int x; cin>>x;
            nw[j].pb({x, i});
        }
    }
    REP(j, k) sort(ALL(nw[j]));

    bonus.resize(n);
    REP(i, n){
        bonus[i].resize(k);
        REP(j, k){
            cin>>bonus[i][j];
        }
    }

    // initial
    queue<int> qu;
    REP(j, k){
        for (int &i = nwptr[j]; i < n && nw[j][i].f <= val[j]; i++){
            sat[nw[j][i].s]++;
            if (sat[nw[j][i].s] == k) {
                qu.push(nw[j][i].s);
            }
        }
    }
    int ans = 0;
    while(SZ(qu)){
        ans++;
        int x = qu.front(); qu.pop();
        REP(l, k){
            val[l] += bonus[x][l];
        }

        REP(j, k){
            for (int &i = nwptr[j]; i < n && nw[j][i].f <= val[j]; i++){
                sat[nw[j][i].s]++;
                if (sat[nw[j][i].s] == k) {
                    qu.push(nw[j][i].s);
                }
            }
        }
    }
    cout<<ans<<endl;
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...