I know this can be done by sorting the array and taking the larger numbers until the required condition is met. That would take at least nlog(n) sorting time.
Is there a
Sum elements highest to lowest in the sorted order till you exceed S.