CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » February Cook - Off Challenge » Dance Floor Energy

Dance Floor Energy

Problem code: ENERGY

  • All Submissions

All submissions for this problem are available.

The Chef is catering a dinner that will be followed by a dance. Unfortunately, the person in charge of organizing the dance has just become ill. The Chef still wants the dance to be successful since it is associated with the dinner he prepared. If the dance is not successful, then it may inadvertently leave a negative impression of the Chef's catering business on the guests.

The Chef has never organized a dance before and now he needs your help. The most complicated task the Chef has to undertake is the following. A dance is only successful if many people are on the dance floor. Thankfully, the guests are shy and are willing to be ordered to dance with other guests they like. The Chef knows which guests each person is willing to dance with and his goal is to have, at any moment in time, the maximum possible number of dancing pairs. A pair of guests will only dance if each is interested in dancing with the other.

To complicate matters, each guest may come and go at different parts of the dance. Specifically, each guest enters the dance only one time, stays for a non-zero length of time, and then leaves the dance and does not return. The Chef is only interested in maximizing the number of dancing pairs at any given moment in time. He is not concerned with repeatedly swapping people to new dance partners, so if a new person enters the dance then the Chef may break up many different dancing couples at this time and form new pairs to maximize the number of dancing pairs.

Say B is the total number of boys on the guest list and G is the total number of girls on the guest list. Your goal is the following. For each integer m between 0 and min(B,G), you should determine the total time that the maximum number of couples that the Chef can assign to the dance floor is m.

Input

The first line contains a single positive integer T ? 30 describing the number of test cases. Each test case begins with three positive integers B, G, and L. B is the number of boys that will attend the dance and G is the number of girls. L indicates the length of the dance.

B lines then follow, each describing a boy. Each such line begins with three integers S,T,N where 0 ? S < T ? L and 0 ? N ? G. Here, S is number of seconds after the dance starts that the boy enters and T is the number of seconds after the dance starts when the boy leaves. Then N distinct integers between 0 and G-1 follow on the same line that describe the girls that the boy is interested in dancing with.

Then G lines follow, each describe a girl in the same manner. The only difference is that 0 ? N ? B and the last N integers on a line corresponding to a girl are distinct integers between 0 and B-1 describing the boys that the girl is interested in dancing with.

Bounds: Both B and G are integers between 1 and 200 and L is an integer between 1 and 1,000,000,000.

Output

You should output a single line for each test case consisting of min(G,B)+1 integers separated by a single space. Starting at index m = 0, the m'th such integer denotes the total time that the maximum number of dancing pairs that can be formed is m. Notice that the sum of the numbers on the output line should be exactly L.

Recall that a pair between a particular boy and a particular girl can only be formed at a given moment of time if both are present at that time and each is interested in dancing with the other.

Example

Input:
4
2 3 10
0 10 2 0 1
1 6 3 0 2 1
4 5 2 0 1
3 8 1 1
2 8 1 0
3 3 20
0 12 3 0 1 2
1 13 3 0 1 2
2 14 3 0 1 2
3 15 3 0 1 2
4 16 3 0 1 2
5 17 3 0 1 2
4 3 40
0 17 3 0 1 3
5 34 2 2 3
21 40 3 0 1 2
1 35 2 3 1
0 27 2 0 3
11 40 4 0 1 2 3
5 29 3 0 2 1
1 1 10
0 5 1 0
5 10 1 0

Output:
7 2 1
9 2 2 7
0 16 18 6
10 0

Test Case Annotation

For the first test case, we have:

From time 0 to 3, no pairs can be formed.

From time 3 to 4, one pair can be formed.

From time 4 to 5, two pairs can be formed.

From time 5 to 6, one pair can be formed.

From time 6 to 10, no pairs can be formed.

So, the total time with m = 0 is 7, the total time with m = 1 is 2, and the total time with m = 2 is 1.


Author: friggstad
Date Added: 4-02-2011
Time Limit: 3 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

you should determine the

javasoul @ 20 Feb 2011 09:41 PM

you should determine the total time that the maximum number of couples that the Chef can assign to the dance floor is m.???

In third sample case: 4 3 400

mmaxio @ 20 Feb 2011 11:37 PM

In third sample case:

4 3 40
0 17 3 0 1 3
5 34 2 2 3
21 40 3 0 1 2
1 35 2 3 1
0 27 2 0 3
11 40 4 0 1 2 3
5 29 3 0 2 1

B = 4, G = 3


Boy 0 can dance with girls 0, 1 and 3, right? But it's said that all girls' numbers are betweeen 0 and G - 1 so there is no girl numbered 3. Where is mistake?

@ Mikhail You are right. The

zac_adm @ 20 Feb 2011 11:49 PM

@ Mikhail

You are right. The original test case was:

4 4 40
0 17 3 0 1 3
5 34 2 2 3
21 40 3 0 1 2
1 35 2 3 1
0 27 2 0 3
11 40 4 0 1 2 3
5 29 3 0 2 1
0 40 0

with output
0 16 18 6 0

I revised it, but neglected to make all the necessary adjustments. Sorry for the confusion.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com