This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pp pair<ll,int>
#define ub(x,i) upper_bound(all(x),i)-x.begin()
using namespace std;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,k;cin>>n>>k;
pii a[k][n];
int u[n][k];
for(int i=0;i<n;i++)for(int j=0;j<k;j++)cin>>a[j][i].f,a[j][i].s=i;
for(int i=0;i<n;i++)for(int j=0;j<k;j++)cin>>u[i][j];
for(int i=0;i<k;i++)sort(a[i],a[i]+n);
int idx[k]={0},cnt[n]={0},v[k]={0};
int rs=0;
while(1){
queue<int>q;
for(int i=0;i<k;i++){
while(idx[i]<n&&v[i]>=a[i][idx[i]].f){
cnt[a[i][idx[i]].s]++;
if(cnt[a[i][idx[i]].s]==k)q.push(a[i][idx[i]].s);
idx[i]++;
}
}if(q.empty())break;
while(!q.empty()){
int x=q.front();q.pop();
for(int i=0;i<k;i++)v[i]+=u[x][i];
rs++;
}
}cout<<rs;
}
# | 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... |