Cowmpetency

My original solution was actually pretty on-target for this one, and just missed by a bit. I got stumped by making sure that changes made to make one constraint true wouldn't disrupt another pair, but I didn't even think about the fact that I could just use a prefix-sum-like idea to store the his for every i.

In the future, I probably want to start with a brute-force solution and gradually make it more efficient.

My Original Pseudo-Code

take in input
make a copy of the original c array, make all changeable values 1
sort the Q pairs by a
for each Q pair:
	find the max value in the section from 1 to a: P
	check all the numbers between a and b for a number that's greater than the max
			work back from a to the beginning of the section, and change the first one that's changeable to be equal to the one that's greater than the max
		if there is
				set b equal to 1+ that
			if there are no changeable ones:
				-1
		else
			make b equal to 1+ the max
		

final pass where you try to lower all the numbers if possible, check to see that everything is correct (including that upper_bound C constraint)

This pseudo-code is robust enough that I'll skip the implementation.

Last updated