My code is giving correct output on ide but here it is showing testcases failed..Whats the mistake

hello @garganshul151

image
this is not correct .
because here u will sort only f array without changing s.
but because f and s are related ,sorting of f should also change s.

read them as pairs and then sort that pairs.

https://ide.codingblocks.com/s/288072…i have updated but output is same…plz see

reply please to this

also tell why greedy approach is necessary here and why we cant do without sorting?

why r u using array after sorting vector of pairs?
use pairs only for ur furthur algorithm.
u logic is correct. just u need to use pair.

check this ->