Submission #1291622

#TimeUsernameProblemLanguageResultExecution timeMemory
12916221otaTopical (NOI23_topical)C++20
40 / 100
1095 ms23800 KiB
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second
#define entire(x) (x).begin(), (x).end()

int32_t main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, k; cin >> n >> k;

    vector<vector<int>> a(n, vector<int>(k, 0)), b(n, vector<int>(k, 0));
    for (int i = 0; i < n; i++) for (int j = 0; j < k; j++) cin >> a[i][j];
    for (int i = 0; i < n; i++) for (int j = 0; j < k; j++) cin >> b[i][j];

    int ans = 0;

    vector<int> cur(k, 0);
    vector<bool> vis(n, false);

    auto add = [&](){
        for (int i = 0; i < n; i++){
            if (vis[i]) continue;
            
            bool ok = true;
            for (int j = 0; j < k; j++) ok &= (a[i][j] <= cur[j]);
            if (ok){
                for (int j = 0; j < k; j++) cur[j] += b[i][j];
                vis[i] = true; return true;
            }
        }
        return false;
    };

    for (int i = 0; i < n; i++){
        if (!add()) break;
        ans++;
    }

    cout << ans << endl;

    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...