I am not able to understand editorial for this problem - https://csacademy.com/contest/fii-code-2020-final-round-mirror/task/traveling-time/
Any other but understandable solution would also be fine.
Thanks.
I am not able to understand editorial for this problem - https://csacademy.com/contest/fii-code-2020-final-round-mirror/task/traveling-time/
Any other but understandable solution would also be fine.
Thanks.
hello @yuvi2701 please share the link of the editorial as well .
i will try to explain editorial first and then i would try to explain any other approach .
I read the code but its not clear. Can you please tell why do we sort by (t_i - l_i) ? Sorting by t_i is understandable. Sorting by l_i is understandable. But why by (t_i - l_i) ?
HELLO @yuvi2701 please see this line in editorial :
We will sort the trains by t_i - li
and in case of equality by li.
. This way, we cannot take a train i after taking a train j>i because we would be behind it.
Suppose
l1 = 1 , t1 = 4
l2 = 8 , t2 = 9
Then (t2 - l2) < (t1 - l1). But we can take train 2 after train 1.
I just don’t understand core idea behind sorting with (ti - li).
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.