No.914 Omiyage
タグ : / 解いたユーザー数 316
作問者 :
tarattata1
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
Problem Statement
Kuru-kun has decided to go on a trip around $N$ countries.
Every country has $M$ kinds of souvenirs, and the prices of the souvenirs in country $i$ are $A_{i,1},A_{i,2},\dots,A_{i,M}$ yen, respectively.
Kuru-kun wants to buy souvenirs in each country to remember the trip.
However, since he has only $K$ yen, he has decided to buy exactly $1$ souvenir in each country.
When he spends as much money as possible, how much money will remain?
Input
$N\ M\ K$
$A_{1,1}\ A_{1,2}\ \dots\ A_{1,M}$
$A_{2,1}\ A_{2,2}\ \dots\ A_{2,M}$
$\vdots$
$A_{N,1}\ A_{N,2}\ \dots\ A_{N,M}$
All inputs are integers.
$1 \le N,M \le 10$
$1 \le K \le 500$
$1 \le A_{i,j} \le 50\ (1 \le i \le N,1 \le j \le M)$
$A_{i,j} < A_{i,j+1}\ (1 \le i \le N,1 \le j \le M-1)$
Output
Output the amount of remaining money on one line. If there is even 1 country where he cannot buy a souvenir, output $-1$. Print a newline at the end.
Sample
Sample 1
Input
3 2 10 1 2 4 5 3 6
Output
0
By spending $2$ yen in country $1$, $5$ yen in country $2$, and $3$ yen in country $3$, he can spend a total of $10$ yen, and the remaining money is $0$ yen.
Sample 2
Input
2 3 5 1 3 4 5 8 10
Output
-1
There is a country where he cannot buy a souvenir, so output $-1$.
Sample 3
Input
4 3 15 1 11 21 2 12 22 3 13 23 4 14 24
Output
5
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。