Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

### desikachariar's blog

By desikachariar, 5 years ago, ,

I submitted a solution for the problem "http://codeforces.com/problemset/problem/14/B" Though the solution has a logical bug, It ran perfectly in my system (gave a output) but when submitted here it gave a runtime error. This happens sometimes with my friend also here. Can anyone help me with how this happened.

Submissions: http://codeforces.com/contest/14/submission/11125428 (without '#define's)

• +1

 » 5 years ago, # | ← Rev. 2 →   +4 size() method returns an unsigned integer, so if les is empty then les.size()-1 overflows and becomes a large positive value.Upd: the difference between your local run and Codeforces is probably the sizes of integer types. On my system sizeof(size_t) = sizeof(long long int) = 8, on Codeforces sizeof(size_t) = 4, sizeof(long long int) = 8.
•  » » 5 years ago, # ^ |   0 That was very useful. Thanks for helping.
•  » » » 5 years ago, # ^ |   +5 I can see how thankful you are from your profile pic :P
 » 5 years ago, # |   +1 ill countl = les.size()-1vector's size can be 0, and it is unsigned int. So count1 will be very big number. Just write:ill count1 = int(les.size())-1
•  » » 5 years ago, # ^ |   0 But then It should overflow in my system also right. Also ill is not unsigned but signed only. Anyway thanks for replying. I got where my mistake could be. I'll avoid writing like this next time.Thanks again.
 » 5 years ago, # |   0 while(countl >= 0 and les[countl] >= i)The problem lies in this line If count is -1 or less than 0 First condition is false but it still evaluates the second condition and returns falseSo in that way you are trying to access count[-1] To avoid this give the second condition inside the loop
•  » » 5 years ago, # ^ |   +6 As far as I know, it doesn't evaluate the second condition if the first is false, I always use this and never got a runtime error because of it .