#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ed "\n"
#define fi first
#define se second
#define db double
#define irs insert
#define pb push_back
#define mpa make_pair
#define pi pair<int,int>
#define MASK(i) (1LL << (i))
#define BIT(x, i) ((x>>i)&1)
#define ON(x, i) ((x) MASK(i))
#define OFF(x, i) ((x) & ~MASK(i))
#define ALL(v) v.begin() , v.end()
#define bp(x) __builtin_popcount(x)
#define pii pair<int,pair<int,int>>
#define fl(i,a,b) for(int i=a;i>=b;--i)
#define fis(i,a,b) for(int i=a;i<=b;++i)
#define Radian(x) (x * acos(-1.0) / 180)
const double eps = 1e-9;
const int mod=1e9+7;
const int Mdem=998244353;
const int LOG=19;
const int base=31;
const int maxn=1e6+5;
const int bl = 320;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define gay(a) freopen(a".inp","r",stdin),freopen(a".out","w",stdout)
template <class T>
bool minimize(T &a, const T &b) {
if(a > b) {a = b; return 1;}
return 0;
}
template <class T>
bool maximize(T &a, const T &b) {
if(a < b) {a = b; return 1;}
return 0;
}
template <class T>
void compress(vector <T> &v) {
sort(ALL(v));
v.erase(unique(ALL(v)), (v).end());
}
void add(int &a, int b) { a += b; if (a >= mod) a -= mod; }
void sub(int &a, int b) { a -= b; if (a < 0) a += mod; }
int n, k;
vector<vector<int>> r, u;
vector<vector<pi>> cd;
int cnt[maxn];
int pos[maxn];
int h[maxn];
signed main(){
fast;
cin >> n >> k;
r = vector<vector<int>> (n + 5, vector<int>(k + 5));
u = vector<vector<int>> (n + 5, vector<int>(k + 5));
cd.resize(k + 2);
fis(i, 1, n) fis(j, 1, k){
cin >> r[i][j];
cd[j].pb({r[i][j], i});
}
fis(i, 1, k) sort(ALL(cd[i]));
fis(i, 1, n) fis(j, 1, k){
cin >> u[i][j];
}
int ans = 0;
while(1){
bool stop = 1;
fis(i, 1, k){
while(pos[i] < n && h[i] >= cd[i][pos[i]].fi){
cnt[cd[i][pos[i]].se]++;
// cout << cd[i][pos[i]].se << ed;
if(cnt[cd[i][pos[i]].se] == k){
// cout << "xx " << cd[i][pos[i]].se << ed;
stop = 0;
ans++;
fis(j, 1, k) h[j] += u[cd[i][pos[i]].se][j];
}
pos[i]++;
}
}
if(stop) break;
}
cout << ans << ed;
return 0;
}
| # | 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... |