Why i am getting TLE, since my solution is of O(n) whereas acc to constarints it can be accepted in o(nlogn)?
Why i am getting TLE, since my solution is of O(n) whereas acc to constarints it can be accepted in o(nlogn)?
@amandeepdogra65, since input can be very large so reading with cin can be time consuming so you have to use fast I/O ,
add these lines at the starting of main function
ios_base::sync_with_stdio(false);
cin.tie(NULL);
or use scanf and printf for fast I/O
as scanf and printf is faster than cin and cout
Here i have corrected your code :-
refer this for more details:-