#P3347. [ZJOI2015] 醉熏熏的幻想乡

[ZJOI2015] 醉熏熏的幻想乡

Description

The tsundere girl Yuuka is a very cute girl. Recently, for some reason, everyone in Gensokyo has been drinking like crazy. Soon the supply of alcohol cannot keep up with demand. To meet everyone’s needs, Yuuka decides to brew alcohol in the forest.

After investigation, Yuuka finds that some places in the forest are very suitable for brewing, while others are very suitable for storage. She calls the places suitable for brewing the brewing sites. Assume there are nn brewing sites, numbered from 11 to nn. There are also mm storage sites, numbered from 11 to mm. There are channels between some brewing sites and storage sites. If there is a channel between brewing site ii and storage site jj, then the alcohol produced at ii can be transported to jj.

Brewing at a site consumes Yuuka’s magic. Due to management factors, at brewing site ii, producing xx liters of alcohol costs aix2+bixa_i \cdot x^2 + b_i \cdot x magic. Note that xx does not have to be a nonnegative integer; it can be any nonnegative real number. Also, at this site at most cic_i liters can be produced. Each storage site jj has a capacity djd_j, meaning this storage site can store at most djd_j liters of alcohol.

Yuuka plans to store as much alcohol as possible, so she will produce some alcohol at certain brewing sites and transport it through the channels to the storage sites. Of course, Yuuka wants to save her magic, so please help her compute, under the requirement of storing the maximum possible amount, what the minimum magic cost is.

Input Format

The first line contains two positive integers nn, mm, the numbers of brewing sites and storage sites. The next nn lines, on the ii-th line are three numbers aia_i, bib_i, cic_i, representing the cost coefficients and the production upper bound at brewing site ii. The next line contains mm integers, which are the values djd_j for each storage site in order. Then there are nn lines, each containing mm numbers. On the ii-th line, the jj-th number indicates whether there is a channel from brewing site ii to storage site jj (11 means there is, 00 means there is not).

Output Format

Output the first line as the maximum total liters of alcohol Yuuka can store (note that this is always an integer; just output the integer).

Output the second line as the minimum magic cost. This is always a rational number; after reduction, output it in the form a/ba/b (if it is 00, output 0/10/1).

10 10
0 2 3
2 3 2
3 1 3
1 2 1
1 0 1
1 1 0
3 3 0
1 2 2
3 1 1
3 1 0
3 1 2 2 3 1 1 2 2 0
0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0
0 0 0 1 0 0 0 0 0 0
1 0 0 0 1 0 0 0 0 0
1 0 1 0 0 0 0 1 1 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 1 0 0 0
0 0 0 0 0 1 0 0 1 0
8
42/1

Hint

  • For 30%30\% of the testdata: all ai=0a_i = 0.
  • For another 30%30\% of the testdata: the denominator of the final answer is 1000\leq 1000.
  • For 100%100\% of the testdata: 1n1001 \leq n \leq 100, 1m1001 \leq m \leq 100.
  • For all testdata, 0ai,bi,ci,di30 \leq a_i, b_i, c_i, d_i \leq 3 and all are integers. Also, for each ii, the number of channels with ai+bi>0a_i + b_i > 0 does not exceed 10001000.
  • Interestingly, for all testdata there exists a positive integer X107X \leq 10^7 such that there is an optimal solution where the amount transported on every path is a multiple of 1/X1/X.

Translated by ChatGPT 5