USACO Silver December 2018 Problem 2 - Convention II

Can someone help me with this Silver problem? I have only been able to get 1/10 test cases.

Problem: http://www.usaco.org/index.php?page=viewproblem2&cpid=859

My Code: https://pastebin.com/P5zn9rMZ

My idea was to input every cow and sort by arrival, then by seniority.

I would then loop through every cow and check it against 3 conditions.

If the cow’s arrival time is greater than the next open time and the priority queue is empty, the next open time is just the arrival time plus the eating time.

If the cow’s arrival time is less than the next open time, push the cow into the line.

If the cow’s arrival time is greater than the next open time, and the priority queue is not empty, process all the cows in the queue.

Process each cow based on seniority, check how long it waited and if it waited the longest, and update the next open time, and remove it from the priority queue.

Once the priority queue is processed, update the next open time.

At the end, output the longest waiting time.

If anyone could take a look at my code (has comments and good variable names), I would greatly appreciated a few pointers!

Thank you :slight_smile:

I can’t really seem to see the problem with your code. Maybe try it with this sample?

2
100 30
100 10

This should output 30, though I’m sure your code works for this.

Please try stress testing first.