Topical

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

Benson the Rabbit is attending pilot school!

He has nn modules to complete, numbered from 11 to nn. There are kk topics in flying numbered from 11 to kk. As Benson is new to flying, he starts with zero knowledge in each topic.

Each of these nn modules have a knowledge requirement to complete them. In particular, to complete module ii, Benson requires at least r\[i]\[j]r\[i]\[j] knowledge of topic jj for all topics jj.

Completing a module also allows Benson to gain knowledge in some topics. After completing module ii, he will gain u\[i]\[j]u\[i]\[j] knowledge in topic jj.

Formally, let Benson’s knowledge in topic jj be p\[j]p\[j]. Initially, p\[j]=0p\[j] = 0 for all jj. He can only complete a module ii if p\[j]r\[i]\[j]p\[j] ≥ r\[i]\[j] for every topic jj. After completing module ii, the value of p\[j]p\[j] increases by u\[i]\[j]u\[i]\[j] for each topic jj.

Benson may complete the modules in any order, but each module may only be completed at most once. Help Benson determine the maximum number of modules he can complete.

입력

The first line of input contains 22 space-separated integers, nn and kk.

Then, nn lines will follow. The ii-th (1in1 ≤ i ≤ n) of these lines contains kk spaced integers r\[i]\[1],r\[i]\[2],,r\[i]\[k]r\[i]\[1], r\[i]\[2], \dots , r\[i]\[k], denoting the knowledge requirements to complete module ii.

Another nn lines follow. The ii-th (1in1 ≤ i ≤ n) of these lines contains kk spaced integers u\[i]\[1],u\[i]\[2],,u\[i]\[k]u\[i]\[1], u\[i]\[2], \dots , u\[i]\[k], denoting the knowledge gained after completing module ii.

출력

The output should contain one integer, the maximum number of modules Benson can complete.

제한

  • 1n,k1061 ≤ n, k ≤ 10^6
  • nk106n \cdot k ≤ 10^6
  • 0u\[i]\[j],r\[i]\[j]1090 ≤ u\[i]\[j], r\[i]\[j] ≤ 10^9 (for all 1in1 ≤ i ≤ n and 1jk1 ≤ j ≤ k).