Programming contests

DEIK Regionális Programozó Csapatverseny, egyetemi kategória, 2024. december 1.

December 1, 2024, 10:00 AM – December 1, 2024, 3:00 PM

Grades

Peter is reviewing his midterm grades—something seems off. He needs to improve a few subjects, but time is limited… He has to plan his improvements: which subjects to focus on, what grades to aim for, and how much time to allocate to each.

He thinks as follows: “I have NN subjects, I know my current grades (g1,,gNg_{1},\ldots,g_{N}), and I have TT time units to prepare. I also know how much time I need to improve in subject ii from a grade of 1 to 2, from 2 to 3, from 3 to 4, or from 4 to 5 (ti,1,ti,2,ti,3,ti,4t_{i,1},t_{i,2},t_{i,3},t_{i,4}). Naturally, if I want to improve from 2 to 4 in subject ii, I need ti,2+ti,3t_{i,2}+t_{i,3} time to prepare. I absolutely don’t want to fail any subjects, so I must improve all grades of 1. Within the given time limit TT, what is the best average grade I can achieve?”

Let’s help him answer this question!

Example:

N=2
current grades: 1, 2
T=20
the needed preparing times:
1. subject: 8 8 9 10
2. subject: 2 3 4 5
He has two choices:
- Improve in the 1. subject to 2, and devote the remaining to the 2. subject
    This way 8+(3+4+5) time units used, and the average is 3.5.
- Improve to 3 in each subjects.
    This way (8+8)+3 time units used, and the average is 3.0.

Input specification

The first line contains the number of subjects, NN. The second line lists the current grades, g1,,gNg_{1},\ldots,g_{N}. The third line contains the available time, TT. The following NN lines each contain the times required for improvement, ti,1ti,4i=1,,Nt_{i,1}\le \ldots \le t_{i,4}\ \ i=1,\ldots ,N The numbers on each line are separated by spaces.

Output specification

If it is possible to improve all grades to at least a 2, output the best achievable average rounded to 2 decimal places on a single line. Otherwise, output the string :-( on a single line.

Constraints

1N1_0001\le N \le 1\_000
1gi51\le g_{i} \le 5
0T1_000_000_0000\le T \le 1\_000\_000\_000
1ti,1ti,2ti,3ti,41_0001\le t_{i,1}\le t_{i,2}\le t_{i,3}\le t_{i,4} \le 1\_000

Sample input 1

  1. 6
  2. 1 2 2 1 1 1
  3. 24
  4. 1 2 3 4
  5. 2 2 2 2
  6. 3 6 10 15
  7. 4 4 5 6
  8. 10 10 11 12
  9. 10 10 10 10
download as text file

Sample output 1

  1. :-(
download as text file

Sample input 2

  1. 6
  2. 1 2 2 1 1 1
  3. 35
  4. 1 2 3 4
  5. 2 2 2 2
  6. 3 6 10 15
  7. 4 4 5 6
  8. 10 10 11 12
  9. 10 10 10 10
download as text file

Sample output 2

  1. 2.67
download as text file

Sample input 3

  1. 2
  2. 2 2
  3. 13
  4. 1 5 30 30
  5. 1 5 6 6
download as text file

Sample output 3

  1. 3.00
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024