제출 #1102320

#제출 시각아이디문제언어결과실행 시간메모리
1102320SoMotThanhXuanTopical (NOI23_topical)C++17
100 / 100
461 ms95676 KiB
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 1;
int N, K, res;
int last[maxN], complete[maxN];
vector<pair<int, int>> r[maxN];
vector<int> u[maxN];
long long p[maxN];
int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> N >> K;
    for(int i = 1; i <= N; ++i){
        for(int j = 1, x; j <= K; ++j){
            cin >> x;
            r[j].push_back(make_pair(x, i));
        }
    }
    for(int i = 1; i <= K; ++i)sort(r[i].begin(), r[i].end());
    for(int i = 1; i <= N; ++i){
        for(int j = 1, x; j <= K; ++j){
            cin >> x;
            u[i].push_back(x);
        }
    }
    int res = 0;
    while(true){
        vector<int> pass;
        for(int j = 1; j <= K; ++j){
            while(last[j] < N && r[j][last[j]].first <= p[j]){
                int i = last[j];
                ++complete[r[j][i].second];
                if(complete[r[j][i].second] == K)pass.push_back(r[j][i].second);
                ++last[j];
            }
        }
        if(pass.empty())break;
        res += pass.size();
        for(int j = 1; j <= K; ++j){
            for(int id : pass){
                p[j] += u[id][j - 1];
            }
        }
    }
    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...