Time Limit: 4000/2000 MS (Java/Others)

Memory Limit: 524288/524288 K (Java/Others)

C-bacteria takes charge of two kinds of videos: ’The Collection of Silly Games’ and ’The Collection of Horrible Games’.

For simplicity’s sake, they will be called as videoA and videoB.

There are some people who want to watch videos during today, and they will be happy after watching videos of C-bacteria.

There are n hours a day, m videos are going to be show, and the number of people is K.

Every video has a type(videoA or videoB), a running time, and the degree of happi- ness after someone watching whole of it.

People can watch videos continuous(If one video is running on 2pm to 3pm and another is 3pm to 5pm, people can watch both of them).

But each video only allows one person for watching.

For a single person, it’s better to watch two kinds to videos alternately, or he will lose W happiness.

For example, if the order of video is ’videoA, videoB, videoA, videoB, …’ or ’B, A, B, A, B, …’, he won’t lose happiness; But if the order of video is ’A, B, B, B, A, B, A, A’, he will lose 3W happiness.

Now you have to help people to maximization the sum of the degree of happiness.

For simplicity’s sake, they will be called as videoA and videoB.

There are some people who want to watch videos during today, and they will be happy after watching videos of C-bacteria.

There are n hours a day, m videos are going to be show, and the number of people is K.

Every video has a type(videoA or videoB), a running time, and the degree of happi- ness after someone watching whole of it.

People can watch videos continuous(If one video is running on 2pm to 3pm and another is 3pm to 5pm, people can watch both of them).

But each video only allows one person for watching.

For a single person, it’s better to watch two kinds to videos alternately, or he will lose W happiness.

For example, if the order of video is ’videoA, videoB, videoA, videoB, …’ or ’B, A, B, A, B, …’, he won’t lose happiness; But if the order of video is ’A, B, B, B, A, B, A, A’, he will lose 3W happiness.

Now you have to help people to maximization the sum of the degree of happiness.

Multiple query.

On the first line, there is a positive integer T, which describe the number of data. Next there are T groups of data.

for each group, the first line have four positive integers n, m, K, W : n hours a day, m videos, K people, lose W happiness when watching same videos).

and then, the next m line will describe m videos, four positive integers each line S, T, w, op : video is the begin at S and end at T, the happiness that people can get is w, and op describe it’s tpye(op=0 for videoA and op=1 for videoB).

There is a blank line before each groups of data.

T<=20, n<=200, m<=200, K<=200, W<=20, 1<=S<T<=n, W<=w<=1000,

op=0 or op=1

On the first line, there is a positive integer T, which describe the number of data. Next there are T groups of data.

for each group, the first line have four positive integers n, m, K, W : n hours a day, m videos, K people, lose W happiness when watching same videos).

and then, the next m line will describe m videos, four positive integers each line S, T, w, op : video is the begin at S and end at T, the happiness that people can get is w, and op describe it’s tpye(op=0 for videoA and op=1 for videoB).

There is a blank line before each groups of data.

T<=20, n<=200, m<=200, K<=200, W<=20, 1<=S<T<=n, W<=w<=1000,

op=0 or op=1

提交代码