I try to solve Different Summands problem with greedy algorithm 

**Problem Description**

**Task**. The goal of this problem is to represent a given positive integer as a sum of as many pairwise
distinct positive integers as possible. That is, to find the maximum  such that  can be written as
`1 + 2 + · · · +`  where `1, . . . ,`  are positive integers and  `̸=`  for all `1 ≤ < ≤ .`

**Input Format.** The input consists of a single integer .
Constraints. `1 ≤ ≤ 10^9`.

**Output Format.** In the first line, output the maximum number  such that  can be represented as a sum
of  pairwise distinct positive integers. In the second line, output  pairwise distinct positive integers
that sum up to  (if there are many such representations, output any of them).

**My Code:** 

```
public class DifferentSummands {
    private static List<Integer> optimalSummands(int n) {
        List<Integer> summands = new ArrayList<Integer>();
        int start = 1;
        int newNumber = n;

        if (n == 2) {
            summands.add(2);
            return summands;
        }

        while (true) {
            if (summands.contains(newNumber - start)) {
                start++;
                continue;
            } else {
                newNumber -= start;
                summands.add(start);
                start++;
            }

            if (newNumber == 0) {
                return summands;
            }
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<Integer> summands = optimalSummands(n);
        System.out.println(summands.size());

        for (Integer summand : summands) {
            System.out.print(summand + " ");
        }
    }
}

```

My code fails if the input was so big it takes about 3.24 seconds and the max time available is 1.5 seconds.