#include <bits/stdc++.h>
using namespace std;
int n, k;
int r[1005][1005];
int u[1005][1005];
bool cmp(int a, int b){
long long sa = 0, sb = 0;
for(int j = 0; j < k; j++){
sa += r[a][j];
sb += r[b][j];
}
return sa < sb;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
int p[k + 1] = {0};
bool done[n + 1] = {false};
int id[n + 1];
for(int i = 0; i < n; i++){
for(int j = 0; j < k; j++){
cin >> r[i][j];
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < k; j++){
cin >> u[i][j];
}
}
for(int i = 0; i < n; i++) id[i] = i;
sort(id, id + n, cmp);
int completed = 0;
bool progress = true;
while(progress){
progress = false;
for(int ii = 0; ii < n; ii++){
int i = id[ii];
if(done[i]) continue;
bool can = true;
for(int j = 0; j < k; j++){
if(p[j] < r[i][j]){
can = false;
break;
}
}
if(can){
done[i] = true;
completed++;
progress = true;
for(int j = 0; j < k; j++){
p[j] += u[i][j];
if(p[j] > 1000000000){
p[j] = 1000000000;
}
}
}
}
}
cout << completed;
}
| # | 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... |