eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Perspective

Perspective

Breaking news! A Russian billionaire has bought a yet undisclosed NBA team. He's planning to invest huge effort and money into making that team the best. And in fact he's been very specific about the expected result: the first place. Being his advisor, you need to determine whether it's possible for your team to finish first in its division or not. More formally, the NBA regular season is organized as follows: all teams play some games, in each game one team wins and one team loses. Teams are grouped into divisions, some games are between the teams in the same division, and some are between the teams in different divisions. Given the current score and the total number of remaining games for each team of your division, and the number of remaining games between each pair of teams in your division, determine if it's possible for your team to score at least as much wins as any other team in your division. \InputFile The first line of input contains \textit{N} (2 ≤ \textit{N} ≤ 20) --- the number of teams in your division. They are numbered from 1 to \textit{N}, your team has number 1. The second line of input contains \textit{N} integers \textit{w}_1, \textit{w}_2,..., \textit{w}_N, where \textit{w}_i is the total number of games that \textit{i}^th team has won to the moment. The third line of input contains \textit{N} integers \textit{r}_1, \textit{r}_2,..., \textit{r}_N, where \textit{r}_i is the total number of remaining games for the \textit{i}^th team (including the games inside the division). The next \textit{N} lines contain \textit{N} integers each. The \textit{j}^th integer in the \textit{i}^th line of those contains \textit{a}_ij --- the number of games remaining between teams \textit{i} and \textit{j}. It is always true that \textit{a}_ij=a_ji and \textit{a}_ii=0, for all \textit{i} \textit{a}_i1 + \textit{a}_i2 +... + \textit{a}_iN ≤ \textit{r}_i. All the numbers in input are non-negative and don't exceed 10\,000. \OutputFile On the only line of output, print "YES" (without quotes) if it's possible for the team 1 to score at least as much wins as any other team of its division, and "NO" (without quotes) otherwise.
Лимит времени 2 секунды
Лимит использования памяти 256 MiB
Входные данные #1
3
1 2 2
1 1 1
0 0 0
0 0 0
0 0 0
Выходные данные #1
YES
Автор Пётр Митричев
Источник Зимняя школа, Харьков 2011, День 8