i pasted #pragma GCC optimize “trapv” on top of my program… still shows wrong answer.
also pls explain me whats wrong in my program, i didnt get u actually
Gah - looks like this trick doesn’t work in some cases - presumably when the result of a computation does not cause overflow, but assigning the result to an int does.
Anyway, you’re getting overflow because there are testcases which would cause p1 and p2 to be assigned values that ints are two small to contain.
Declare p1 and p2 as ll instead of int and try again.