Fill the Matrix
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
Description
There is a square matrix, consisting of rows and columns of cells, both numbered from to . The cells are colored white or black. Cells from to are black, and cells from to are white, in the -th column.
You want to place integers in the matrix, from to . There are two rules:
- each cell should contain at most one integer;
- black cells should not contain integers.
The beauty of the matrix is the number of such that is written in the same row, in the next column as (in the neighbouring cell to the right).
What's the maximum possible beauty of the matrix?
The first line contains a single integer () — the number of testcases.
The first line of each testcase contains a single integer () — the size of the matrix.
The second line contains integers () — the number of black cells in each column.
The third line contains a single integer () — the number of integers you have to write in the matrix. Note that this number might not fit into a 32-bit integer data type.
The sum of over all testcases doesn't exceed .
For each testcase, print a single integer — the maximum beauty of the matrix after you write all integers in it. Note that there are no more integers than the white cells, so the answer always exists.
Input
The first line contains a single integer () — the number of testcases.
The first line of each testcase contains a single integer () — the size of the matrix.
The second line contains integers () — the number of black cells in each column.
The third line contains a single integer () — the number of integers you have to write in the matrix. Note that this number might not fit into a 32-bit integer data type.
The sum of over all testcases doesn't exceed .
Output
For each testcase, print a single integer — the maximum beauty of the matrix after you write all integers in it. Note that there are no more integers than the white cells, so the answer always exists.
比赛1
- Status
- Done
- Rule
- IOI
- Problem
- 6
- Start at
- 2023-6-14 10:45
- End at
- 2023-6-14 12:45
- Duration
- 2 hour(s)
- Host
- Partic.
- 8