although i have got AC(by modifying the above) but i am not able to understand why this solution is throwing "terminate called after throwing an instance of__gnu_cxx::__concurrence_lock_error" error on inputs like( 1 100 10 1).FYI the problem is of atcoder dp contest (C).sorry for asking doubts from other platfrom .thanks in advance!
atcoder dp contest (C)