magic square operations

Fill in the grid with the numbers $$1$$ to $$6$$ so that each number appears exactly once in each row and column. A horizontal gray line marks any cell when it is the middle cell of the three consecutive cells with the largest sum in that row. Similarly, a vertical gray line marks any cell when it is the middle of the three consecutive cells with the largest sum in that column. If there is a tie, multiple lines are drawn in the row or column. A cell can have both lines drawn, with the appearance of a plus sign.

For example, if a filled row had $$1 5 4 2 3 6$$, horizontal lines would be drawn in the two cells with $$4$$ and $$3$$, since out of $$1 + 5 + 4, 5 + 4 + 2, 4 + 2 + 3,$$ and $$2 + 3 + 6,$$ the largest sums are $$5 + 4 + 2$$ and $$2 + 3 + 6$$.

This contest puzzle is from: https://files.usamts.org/Problems_35_3.pdf

This contest’s submission deadline has passed.

• This was a problem in the recent round of USAMTS problems that closed just yesterday. Posting this here clearly violates the terms of the contest: "Participants may not discuss the problems with others before the deadline for solution submission." You are also posting past USAMTS problems without attribution, giving the impression they are your own. Please desist.
– Stiv
Commented Jan 5 at 0:15
• @Stiv I was unaware of this tournament. Should I delete my answer? Commented Jan 5 at 10:53
• @Toffee As was I - a keen-eyed user mentioned it in chat... I wouldn't delete right now - the contest has closed, we spotted it too late. If the mods think further action is required, they can arrange whatever deletions are necessary. You answered in good faith (it was a good-looking puzzle, I wouldn't have spotted the original source without prompting).
– Stiv
Commented Jan 5 at 13:22

A very neat puzzle! Before we dive in, a couple of lemmas/corollaries:

Lemma 1: Consider the pattern:

We must have A > D

Corollaries: A cannot be 1 and D cannot be 6

Lemma 2: Consider the pattern:

We must have A+B = D+E

Armed with Lemma 1 we get:

Applying our corollary to column 3 forces

The 2 in R6C3 with some more cells coming as a result of lemma 1

Now

To ensure the horizontal bar is in the correct place in column 2, the 3 must be placed in R5C2

This forces

Row 3 into this unique arrangement with respect to the vertical bar

This is where we bring in lemma 2

R2C3 must be one more than R5C3. The only consecutive pair of numbers that fit are 4 and 5

Let’s go back to lemma 1 to get

Now

The 6 in row 5 can only go in one place to ensure the horizontal bar is in the correct place. This gives a lot more cells via the usual Latin square logic.

Finally, using lemma 2

In row 4 forces the final unique solution (which I slipped up on in my original submission - thanks Dante)

• Sums of the two gray marks on the fourth row aren't equal. Commented Jan 2 at 11:10

My solution, also showing the sums

Method:
A tally is kept of the numbers used in each row and column.
Starting with the bottom row, the available numbers are permuted.
For each valid arrangement, the maxima are checked to match the spec.
If the row is good, repeat for the next row up, until the top row is done.
Lastly, check the maxima for each column against the spec.
If they all match, there is a valid solution.

Found by recursive algorithm, before another answer was corrected. The solution is unique.

• I didn't quite post it before the incorrect answer was edited. Commented Jan 2 at 11:35