longest subsequence weighting problem