I am working on Splitting the Field (Problem 1) from the 2016 Gold US Open.

However, my code only works for 6/10 test cases, meaning I have the general idea but there is something that messes up with larger inputs.

My idea was to have four multisets that keep track of the x coordinates on the right and left and the y coordinates on the right and left. I would first sweep through the x coordinates and find the area of both fences and add them together. I would keep track of the smallest two fence perimeter. At the end, I would subtract it from the original one fence area.

Could someone give me some pointers to lead me in the right direction?

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

Solution: https://usaco.guide/solutions/usaco-645?lang=cpp

Code: https://pastebin.com/uAT1RzhG

EDIT: Question solved - I simply set a variable to INT_MAX rather than LL_MAX, so I got integer overflow.

Maybe consider commenting your code so we know what each step is actually doing?

Sorry about that. Just added some comments.

1 Like

EDIT: Question solved - I simply set a variable to INT_MAX rather than LL_MAX, so I got integer overflow.