Submission #1268289

#TimeUsernameProblemLanguageResultExecution timeMemory
1268289vukhacminhTopical (NOI23_topical)C++20
0 / 100
15 ms1860 KiB
/**
*    Author :  Vu Khac Minh
**/
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1e9+7;
int n,k;
vector<int> a[maxn],b[maxn];
vector<pair<int,int>> s[maxn];
int r[maxn],cnt[maxn],power[maxn];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    for(int i = 1;i<=n;i++)
    {
        a[i].resize(k+1);
        b[i].resize(k+1);
    }
    for(int i = 1;i<=n;i++)
    {
        for(int j = 1;j<=k;j++)
            {
                cin>>a[i][j];
                s[j].push_back({a[i][j],i});
            }
    }
    for(int i = 1;i<=n;i++)
    {
        for(int j = 1;j<=k;j++)
            cin>>b[i][j];
    }
    for(int i = 1;i<=k;i++)
    sort(s[i].begin(),s[i].end());
    int res = 0;
    while(true)
    {
        bool stopped = false;
       for(int j = 1;j<=k;j++)
        {
            while(r[j]<=n)
            {
                int x = s[j][r[j]].first;
                int y = s[j][r[j]].second;
                if(x<=power[j])
                {
                    r[j]++;
                    cnt[y]++;
                    if(cnt[y] == k)
                    {
                        for(int i = 1;i<=k;i++)
                            power[i]+=b[y][i];
                        stopped = true;
                        res++;
                    }
                }else break;
            }
        }
        if(!stopped) break;
    }
    cout<<res;
    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...