SRM 704, D2, 250-Pointer (SwapAndArithmetic)

James S. Plank

Fri Feb 3 14:42:38 EST 2017
Try this on your own. If you get stuck, return here and read what I've written below.



























































If you're here, think about how much easier the problem is if you sort the input. Now, go back and try to solve it again, and if you get stuck again, come back.



























































What you want to do is sort the vector. You can do that most easily with the sort() method from the STL algorithms library. You need to include algorithms, and then you can sort the vector with sort(x.begin(), x.end()). Then, the easiest thing to do is try to discover if the vector is not an arithmetic sequence.

The way that I did that was to: