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
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Practice(medium) » Dance Floor Energy

Dance Floor Energy

Problem code: ENERGY

  • Submit
  • 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.

The third test case is still

dj3500 @ 22 Feb 2011 05:35 AM

The third test case is still wrong, doh. The full test is supposed to be:

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 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
1 1 10
0 5 1 0
5 10 1 0

And expected output:

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

@ Jakub Tarnawski No, I think

fura2 @ 30 Mar 2011 07:19 AM

@ Jakub Tarnawski

No, I think all testcases are OK.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold

HELP

Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:

 

  • Accepted Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark.
  • Time Limit Exceeded Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach.
  • Wrong Answer Your program compiled and ran succesfully but the output did not match the expected output.
  • Runtime Error Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section.
  • Compilation Error Your code was unable to compile. When you see this icon, click on it for more information.
  • If you are still having problems, see a sample solution here.

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 algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm 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 programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were 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 challenges 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 coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

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. You can also host a coding contest for your institute on CodeChef, organize an algorithm event 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