Thank you for reply. I figured it out where the bug was in the code.
I did the test when asking this question; however, when it ran on my computer, it was fine, so I didn’t see it through.
But when i tried on a online IDE, it gave exactly what you write above.
The main reason is that in the code, there’s a bug in the condition if (list[j]>limit)
When j> list.size(). My computer gave random number which is larger than the limit, while the online IDE gave 0. So luckily, my computer would still give right answer, but the tester would give wrong one.