Kattis

# Tomography

Binary tomography deals with the problem of reconstructing binary images from a small number of projections. One of its most basic problems is to construct a binary ($\{ 0,1\}$-valued) matrix with given row and column sums. This is not always possible and your task is to determine when it is.

## Input

The first line of input contains two numbers $1\leq m,n\leq 1000$, the number of rows and columns of the matrix. The next line contains $m$ numbers $0\leq r_ i\leq n$ – the sum of each row in the matrix. The third line contains $n$ numbers $0\leq c_ j\leq m$ – the sum of each column in the matrix.

## Output

Output “Yes” if there exists an $m$-by-$n$ matrix $\mathbf{A}$, with each element either beeing 0 or 1, such that

$\sum _{j=1}^ nA_{i,j} = r_ i \; \forall i\in \{ 1,2,\dots ,m\} \textrm{ and } \sum _{i=1}^ mA_{i,j} = c_ j \; \forall j\in \{ 1,2,\dots ,n\} .$

Otherwise output “No”.

## Example

The figure below illustrates a matrix with the row and column sums of sample input 1.

Sample Input 1 Sample Output 1
3 4
2 3 2
1 1 3 2

Yes

Sample Input 2 Sample Output 2
3 3
0 0 3
0 0 3

No
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 2, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.3802291452884674, "perplexity": 250.81907401309584}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 20, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2021-25/segments/1623488286726.71/warc/CC-MAIN-20210621151134-20210621181134-00539.warc.gz"}