3119 - Anders And The Matrix

Created by Luis Manuel Díaz Barón
Added by luismo (2015-02-20)
Limits
Total Time: 5000 MS | Test Time: 1000 MS |Memory: 244 MB | Output: 64 MB | Size: 16 KB
Enabled languages
Available in

Description

Anders the cat, finished watching The Matrix movie, being upset for finding himself unable to understand all the logic behind the main argument of the film, he decided to torture you: his favorite mouse, by locking you into a cubic cell, to be only opened if you manage to solve this “problem”.

Given a square matrix of side length N (N <= 3), and NxN integers, each one lower or equal to 100. Can you find whether these numbers can be placed in, such that rows (from top to bottom, enumerated from 1 to N) sum R1… RN respectively and columns (from left to right, enumerated from 1 to N) sum C1… CN respectively, and the main diagonal sums D1, and its reverse sums D2;jsessionid=99C2448ED1B6E88767A4EC3E4931BF3C?

Anders el gato, terminó de ver la película “The Matrix”, molesto por no poder entender toda la lógica detrás del argumento principal de la película, decidió torturarte: su ratón favorito, encerrándote en una celda cúbica, para ser solo abierta si logras resolver este "problema".

Dados una matriz cuadrada con lados de longitud N (N <= 3) y NxN números enteros, debe usted encontrar si estos números pueden colocarse, de manera que las filas (de arriba a abajo, enumeradas de 1 a N) sumen R1, ..., RN respectivamente, las columnas (de izquierda a derecha, enumeradas de 1 a N) sumen C1, ..., CN respectivamente, la diagonal principal sume D1, y la diagonal inversa sume D2.

Anders the cat, finished watching The Matrix movie, being upset for finding himself unable to understand all the logic behind the main argument of the film, he decided to torture you: his favorite mouse, by locking you into a cubic cell, to be only opened if you manage to solve this “problem”.

Given a square matrix of side length N (N <= 3), and NxN integers, each one lower or equal to 100. Can you find whether these numbers can be placed in, such that rows (from top to bottom, enumerated from 1 to N) sum R1… RN respectively and columns (from left to right, enumerated from 1 to N) sum C1… CN respectively, and the main diagonal sums D1, and its reverse sums D2;jsessionid=99C2448ED1B6E88767A4EC3E4931BF3C?

Input specification

N – the length of the side of the matrix

The next line contains NxN integers, to be placed in the matrix

The third line contains N space separated integers

R1…RN

The fourth line contains N space separated integers, each one lower or equal to 100.

C1…CN

And the fifth line contains 2 separated integers

D1 D2
Línea 1: Contiene un entero N, la longitud de la matriz.
Línea 2: Contiene NxN enteros separados por espacios, los números a ser colocados en la matriz.
Línea 3: Contiene N enteros separados por espacios, R1, …, RN.
Línea 4: Contiene N enteros separados por espacios, C1, …, CN.
Línea 5: Contiene 2 enteros separados por espacios, D1 y D2.
N – the length of the side of the matrix

The next line contains NxN integers, to be placed in the matrix

The third line contains N space separated integers

R1…RN

The fourth line contains N space separated integers, each one lower or equal to 100.

C1…CN

And the fifth line contains 2 separated integers

D1 D2

Output specification

If the numbers can be placed such that the above conditions meet print “Yes” (without quotes), otherwise print “No” (without quotes).

;jsessionid=99C2448ED1B6E88767A4EC3E4931BF3C
Si los números pueden ser colocados de forma tal que las condiciones anteriores se cumplan, imprima “Yes” (sin las comillas), en caso contrario imprima “No” (sin las comillas).
N – the length of the side of the matrix

The next line contains NxN integers, to be placed in the matrix

The third line contains N space separated integers

R1…RN

The fourth line contains N space separated integers, each one lower or equal to 100.

C1…CN

And the fifth line contains 2 separated integers

D1 D2

Sample input

2
1 2 3 4
3 7
4 6
5 5

Sample output

Yes

Hint(s)

http://coj.uci.cu/contest/
http://coj.uci.cu/contest/
http://coj.uci.cu/contest/