Submission #1122795

#TimeUsernameProblemLanguageResultExecution timeMemory
1122795nhphucTopical (NOI23_topical)C++20
100 / 100
595 ms140144 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

int32_t main (){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    if (fopen("test.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    int n, k, ans = 0; cin >> n >> k;
    vector<int> cnt(n + 1), id(k + 1), cur(k + 1);
    vector<vector<int>> r(n + 1, vector<int>(k + 1)), u(n + 1, vector<int>(k + 1));
    vector<pair<int, int>> vec[k + 1];
    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= k; ++j){
            cin >> r[i][j];
        }
    }
    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= k; ++j){
            cin >> u[i][j];
        }
    }
    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= k; ++j){
            vec[j].push_back({r[i][j], i});
        }
    }
    for (int i = 1; i <= k; ++i){
        sort(vec[i].begin(), vec[i].end());
    }
    while (true){
        vector<int> lst;
        for (int i = 1; i <= k; ++i){
            while (id[i] < n && vec[i][id[i]].first <= cur[i]){
                ++cnt[vec[i][id[i]].second];
                if (cnt[vec[i][id[i]].second] == k){
                    lst.push_back(vec[i][id[i]].second);
                }
                ++id[i];
            }
        }
        if (lst.size() == 0){
            break;
        }
        ans += lst.size();
        for (int i : lst){
            for (int j = 1; j <= k; ++j){
                cur[j] += u[i][j];
            }
        }
    }
    cout << ans << "\n";
}

Compilation message (stderr)

Main.cpp: In function 'int32_t main()':
Main.cpp:9:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:10:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...