#include <bits/stdc++.h>
#define int long long
#define REP(v, i, j) for (int v = i; v != j; v++)
#define FORI(v) for (auto i : v)
#define FORJ(v) for (auto j : v)
#define OUT(v, a) \
FORI(v) \
cout << i << a;
#define OUTS(v, a, b) \
cout << v.size() << a; \
OUT(v, b)
#define in(a, n) \
REP(i, 0, n) \
cin >> a[i];
#define SORT(v) sort(begin(v), end(v))
#define REV(v) reverse(begin(v), end(v))
#define MEMSET(m) memset(m, -1, sizeof m)
#define pb push_back
#define fi first
#define se second
#define detachIO \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std;
template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
bool operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) {
if(__x.size() != __y.size()) return false;
return std::equal(__x.begin(), __x.end(), __y.begin());
}
typedef pair<long long, long long> pii;
typedef pair<pii, long long> piii;
typedef pair<pii, pii> piiii;
deque<pair<int,int>> waiting[1000100];
int met[1000100];
vector<int> gain[1000100];
queue<int> available;
int skills[1000100];
int n;
int k;
void sync(){
REP(i,0,k){
while(waiting[i].size()&&waiting[i].front().fi<=skills[i]){
met[waiting[i].front().se]++;
if(met[waiting[i].front().se]==k)available.push(waiting[i].front().se);
waiting[i].pop_front();
}
}
}
signed main(){
detachIO;
cin>>n;
cin>>k;
REP(i,0,n){
REP(j,0,k){
int x;cin>>x;
waiting[j].pb({x,i});
}
}
REP(i,0,n){
REP(j,0,k){
int x;cin>>x;
gain[i].pb(x);
}
}
REP(j,0,k)SORT(waiting[j]);
int ans=0;
sync();
while(available.size()){
auto t=available.front();
ans++;
available.pop();
REP(i,0,k){
skills[i]+=gain[t][i];
}
sync();
}
cout<<ans;
}
# | 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... |