These are links to my 2 submissions: 1) http://mirror.codeforces.com/contest/588/submission/13653807 2) http://mirror.codeforces.com/contest/588/submission/13653815
Only difference between both is that in 1) am using scanf to take input while in 2) am using cin. Although my logic remains the same, I got TLE and possible penalty (if this had happened during contest). Just because I used cin, does it make my submission wrong? If not, should time limits be set such that solutions are not rejected on usage of cin?