#include<bits/stdc++.h>
#define ll long long
#define dn cout << "\n";
#define name "task"
#define pb push_back
#define F first
#define S second
using namespace std;
const int M = 1e6 + 2;
const int N = 1e5 + 2;
int n, k;
void solve(){
cin >> n >> k;
vector<ll> cur(k + 1, 0), cnt(n + 1, 0), pos(k + 1, -1);
vector<vector<int>> a(n + 2, vector<int> (k + 2));
vector<vector<int>> b(n + 2, vector<int> (k + 2));
vector<vector<pair<int,int>>> vec(k + 2);
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= k; j ++){
int x; cin >> x;
a[i][j] = x;
}
}
for(int i = 1; i <= n; i ++){
for(int j = 1; j <= k; j ++){
int x; cin >> x;
b[i][j] = x;
}
}
for(int j = 1; j <= k; j ++){
for(int i = 1; i <= n; i ++){
vec[j].pb({a[i][j], i});
}
sort(vec[j].begin(), vec[j].end());
}
int res = 0;
while(1){
bool check = 0;
for(int j = 1; j <= k; j ++){
while(pos[j] + 1 < n && vec[j][pos[j] + 1].F <= cur[j - 1]){
cnt[vec[j][pos[j] + 1].S] ++;
if(cnt[vec[j][pos[j] + 1].S] == k){
res ++; check = 1;
for(int p = 0; p < cur.size(); p ++) cur[p] += b[vec[j][pos[j] + 1].S][p + 1];
}
pos[j] ++;
}
}
if(check == 0) break;
}
cout << res;
}
main(){
cin.tie(0) -> ios::sync_with_stdio(0);
/*
if(fopen(name".inp","r")){
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
*/
solve();
}
Compilation message (stderr)
Main.cpp:55:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
55 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |