Abstract
In this paper, we address the following problems: Given a sequence A of n real numbers, and four parameters I, J, X and Y with I ≤ J and X ≤ Y, find the longest (or shortest) subsequence of A such that its length is between I and J and its sum is between X and Y. We present an online and an offline algorithm for the problems, both run in O(n log n) time, which are optimal.