#include<bits/stdc++.h>
using namespace std;
#define maxn 1000009
#define ll long long
#define fi first
#define se second
#define pb push_back
#define re exit(0);
#define left id<<1
#define right id<<1|1
#define _lower(x) lower_bound(v.begin(),v.end(),x)-v.begin() + 1
const int mod = 1e9+7;
const int INF = 1e9;
typedef vector<int> vi ;
typedef pair<int,int> pii ;
typedef vector<pii> vii ;
void add ( int &a , int b )
{
a += b ;
if ( a >= mod ) a -= mod ;
if ( a < 0 ) a += mod ;
}
template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ; }
template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ; }
void runfile() { freopen ("bai1.inp","r",stdin) ; }
int _pow ( int a , int n )
{
if ( n == 0 ) return 1 ;
int res = _pow (a,n/2) ;
if ( n % 2 ) return 1ll*res*res%mod*a%mod ;
else return 1ll*res*res%mod ;
}
int n , k ;
vector<int> r [maxn] , u[maxn] ;
int p [maxn] ;
int cnt [maxn] ;
vector<pii> requires [maxn] ;
bool cmp ( pii u , pii v )
{
return u.fi < v.fi ;
}
int cur [maxn] ;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// runfile() ;
cin >> n >> k ;
for ( int i = 1 ; i <= n ; i ++ ) r [i].resize(k+2) , u [i].resize(k+2) ;
for ( int i = 1 ; i <= n ; i ++ ) for ( int j = 1 ; j <= k ; j ++ ) cin >> r [i][j] ;
for ( int i = 1 ; i <= n ; i ++ ) for ( int j = 1 ; j <= k ; j ++ ) cin >> u [i][j] ;
for ( int i = 1 ; i <= k ; i ++ ) p [i] = 0 ;
for ( int j = 1 ; j <= k ; j ++ ) requires[j].resize(n+2) ;
for ( int j = 1 ; j <= k ; j ++ ) for ( int i = 1 ; i <= n ; i ++ ) requires [j][i] = {r[i][j],i} ;
for ( int j = 1 ; j <= k ; j ++ ) sort (requires[j].begin()+1,requires[j].begin()+n+1,cmp) ;
for ( int j = 1 ; j <= k ; j ++ ) cur [j] = 1 ;
int res = 0 ;
while ( true )
{
bool changed = false ;
for ( int j = 1 ; j <= k ; j ++ )
{
while ( p [j] >= requires[j][cur[j]].fi && cur [j] <= n )
{
if ( ++ cnt [requires[j][cur[j]].se] == k )
{
for ( int run = 1 ; run <= k ; run ++ )
{
p [run] += u [requires[j][cur[j]].se][run] ;
}
res ++ ;
}
cur [j] ++ ;
changed = true ;
}
}
if ( changed == false ) break ;
}
cout << res ;
}
Compilation message (stderr)
Main.cpp: In function 'void runfile()':
Main.cpp:29:26: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | void runfile() { freopen ("bai1.inp","r",stdin) ; }
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |