Comments

BledDest MikeMirzayanov

This is regarding an unfair plagiarism check that has occurred with respect to 2043C - Sums on Segments. I have explained below my solution to 2043C - Sums on Segments and the way I have implemented it. Please find my submission link 298237538

I first check if there is an element in the array that is not 1 or -1 which is what the first for loop corresponds to.

If there is no such element, I run Kadane's algorithm to find the maximum and the minimum subarray sums in the whole array.

The implementation I have followed is quite standard and is similar to the one described in pg 104 of Competitive Programming 3 by Steven Halim and Felix Halim.

As the array is made up of only 1 and -1's, the possible subarray sums are from minnsum to maxxsum which I output using another for loop. After this I return from the function solve().

If there was such an element(at idx), I first try to find possible sums corresponding to subarrays not containing that element, for which I use two more runs of Kadane's algorithm, one from 0 to idx-1 and another from idx+1 to n-1. And after each of these runs, I insert all the possible subarray sums into a std::set to ensure I output only distinct elements at the end.

To find the set of sums of subarrays containing the element at idx, I run two other for loops to find out the maximum and minimum sums, one starting from idx+1 and another ending at idx-1 using which I find whatever sums are possible in subarrays containing the element at idx. And again to ensure unique elements, I add them to a set which I use to print my final output.

The above approach is quite easy to think of and is certainly something one can opt to code up under a time constraint. It can also be seen that once one has decided to proceed in the above direction, there isn't much he can do than write the requisite for loops and use the necessary variables.

It is however very disheartening and demotivating to see that my solutions have been skipped stating that there have been similarities with the codes submitted by lexapex5 and code_coffee. I don't know either of them and I'm quite sure they too have honestly solved this problem on their own.

Kindly review my code and do not penalize me for a mistake I have not committed.

Thank you.