SIGSEV in Chef and Cake

My code is running successfully in Code Blocks, but CodeChef is showing Run time error(SIGSEGV). Why is it so?
Link to my code is

You default construct std::string objects in your sample1 and sample2 arrays and then later write to


But you never made sure those strings can hold at least k characters. This is undefined behavior.