「zoj3229」Shoot the Bullet

2014年6月3日5,9792

Gensokyo is a world which exists quietly beside ours, separated by a mystical border. It is a utopia where humans and other beings such as fairies, youkai(phantoms), and gods live peacefully together. Shameimaru Aya is a crow tengu with the ability to manipulate wind who has been in Gensokyo for over 1000 years. She runs the Bunbunmaru News – a newspaper chock-full of rumors, and owns the Bunkachou – her record of interesting observations for Bunbunmaru News articles and pictures of beautiful danmaku(barrange) or cute girls living in Gensokyo. She is the biggest connoisseur of rumors about the girls of Gensokyo among the tengu. Her intelligence gathering abilities are the best in Gensokyo!

During the coming n days, Aya is planning to take many photos of m cute girls living in Gensokyo to write Bunbunmaru News daily and record at least Gx photos of girlx in total in the Bunkachou. At the k-th day, there are Ck targets, Tk1Tk2, …, TkCk. The number of photos of target Tki that Aya takes should be in range [LkiRki], if less, Aya cannot write an interesting article, if more, the girl will become angry and use her last spell card to attack Aya. What’s more, Aya cannot take more than Dkphotos at the k-th day. Under these constraints, the more photos, the better.

Aya is not good at solving this complex problem. So she comes to you, an earthling, for help.

Input

There are about 40 cases. Process to the end of file.

Each case begins with two integers 1 <= n <= 365, 1 <= m <= 1000. Then m integers, G1G2, …, Gm in range [0, 10000]. Then n days. Each day begins with two integer 1 <= C <= 100, 0 <= D <= 30000. Then C different targets. Each target is described by three integers, 0 <= T < m, 0 <= L <= R <= 100.

Output

For each case, first output the number of photos Aya can take, -1 if it’s impossible to satisfy her needing. If there is a best strategy, output the number of photos of each girl Aya should take at each day on separate lines. The output must be in the same order as the input. If there are more than one best strategy, any one will be OK.

Output a blank line after each case.

Sample Input

Sample Output

题解

首先S向每天连[0,day]的边,每一天与拍照的妹子连[l,r]的边,每个女孩和汇连[g,oo]的边

对于有源和汇的上下界网络流,只要T到S连一条[0,inf]的边,那么原图成为一个无源点汇点的循环流图,那么新建SS和TT,向每个点连边(即每一点的入流为正则源向其连,否则向汇连),求SS到TT的最大流判断满流

判断有解之后求最大流再做一次S到T的最大流

同时要去掉原来T到S的[0,inf]的边

 

avatar
2 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
23312315 Recent comment authors
  Subscribe  
提醒
233

这题zoj上好像挂了,一直Judge Internal Error

12315
12315

……..