Submission #1329158

#TimeUsernameProblemLanguageResultExecution timeMemory
1329158octlockTopical (NOI23_topical)C++20
61 / 100
1096 ms126576 KiB
#include <bits/stdc++.h>
#define ll long long
const int N = 1e6+5;
const ll mod = 998244353;
using namespace std;
vector<ll> r[N], u[N];
bool what[N];
vector<pair<ll,ll>> huh;
int n,k;
void solve()
{
    cin >> n >> k;
    for (int i=0;i<n;i++)
    {
        for (int j=1;j<=k;j++)
        {
            ll op; cin >> op;
            r[i].push_back(op);
        }
    }
    for (int i=0;i<n;i++)
    {
        for (int j=1;j<=k;j++)
        {
            ll op; cin >> op;
            u[i].push_back(op);
        }
    }
    if (n == 1)
    {
        for (int i=0;i<k;i++)
        {
            if (r[0][i] > 0)
            {
                cout << "0\n";
                return;
            }
        }
        cout << "1\n";
        return;
    }else if (k == 1)
    {
        ll sus = 0;
        for (int i=0;i<n;i++)
        {
            huh.push_back(make_pair(r[i][0],u[i][0]));
        }
        sort(huh.begin(),huh.end());
        int ans = 0;
        for (pair<ll,ll> i: huh)
        {
            if (sus >= i.first)
            {
                sus += i.second;
                ans++;
            }else
            {
                break;
            }
        }
        cout << ans << '\n';
    }else
    {
        vector<ll> har;
        for (int i=1;i<=k;i++)
        {
            har.push_back(0);
        }
        int ans = 0;
        while (true)
        {
            bool wha = false;
            for (int i=0;i<n;i++)
            {
                if (!what[i])
                {
                    what[i] = true;
                    for (int j=0;j<k;j++)
                    {
                        if (har[j] < r[i][j])
                        {
                            what[i] = false;
                            break;
                        }
                    }
                    if (what[i])
                    {
                        ans++;
                        wha = true;
                        for (int j=0;j<k;j++)
                        {
                            har[j] += u[i][j];
                        }
                    }
                }
            }
            if (!wha)
            {
                break;
            }
        }
        cout << ans << '\n';
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...