Submission #1159465

#TimeUsernameProblemLanguageResultExecution timeMemory
1159465sofija6Topical (NOI23_topical)C++20
100 / 100
379 ms117704 KiB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n,k;
    cin >> n >> k;
    ll r[n+2][k+2],u[n+2][k+2];
    priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > > q[k+2];
    for (ll i=1;i<=n;i++)
    {
        for (ll j=1;j<=k;j++)
        {
            cin >> r[i][j];
            q[j].push({r[i][j],i});
        }
    }
    for (ll i=1;i<=n;i++)
    {
        for (ll j=1;j<=k;j++)
            cin >> u[i][j];
    }
    ll ans=0,val[k+2]={0},cnt[n+2]={0};
    queue<ll> active;
    for (ll i=1;i<=n;i++)
    {
        bool ok=true;
        for (ll j=1;j<=k;j++)
            ok=(ok && !r[i][j]);
        if (ok)
        {
            cnt[i]=k;
            active.push(i);
        }
    }
    while (!active.empty())
    {
        ll ind=active.front();
        active.pop();
        ans++;
        for (ll i=1;i<=k;i++)
        {
            val[i]+=u[ind][i];
            while (!q[i].empty() && q[i].top().first<=val[i])
            {
                cnt[q[i].top().second]++;
                if (cnt[q[i].top().second]==k)
                    active.push(q[i].top().second);
                q[i].pop();
            }
        }
    }
    cout << ans;
    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...