My "keybore" is key-boring me! Help me find a minimal keystrokes Credits to @Agawa001 for coming up with this question.

Explanation

My new "keybore" only has 2 buttons, namely + and -.

The number in the memory starts at 0.

Each consecutive press of + or - will increment/decrement the memory for exactly how many times it has been pressed consecutively.

Therefore, if you press + 4 times, first time it adds 1, the second time it adds 2, the third time it adds 3, the fourth time it adds 4, giving you 10 (ten).

Now, if you press - 3 times, the first time it subtracts 1, the second time 2, the third time 3, leaving you with 4 (four).

TL;DR

Given a string of + and -, divide it at each change of character. Then each resulting string of m + symbols adds the m-th triangle number, and each string of n - symbols subtracts the n-th triangle number.

Walk-through

Now, if you still do not understand, I will show you how +++--+-- creates 1.

Program   | Counter | Memory
----------------------------
          |  0      | 0
+         | +1      | 1
++        | +2      | 3
+++       | +3      | 6
+++-      | -1      | 5
+++--     | -2      | 3
+++--+    | +1      | 4
+++--+-   | -1      | 3
+++--+--  | -2      | 1


Task


You will take a positive integer as input, either as functional argument or from STDIN.
Then, you will output/print the minimum number of keystrokes needed to create that number using the method above.


Testcases

Since rearranging the + or - runs gives the same number, for each such group only the lexicographically earliest sequence is listed.

Input | Output | Possible corresponding sequences
-------------------------------------------------
    4 |      5 | -+++-
    6 |      3 | +++
    9 |      5 | ++++-
   11 |      7 | +++-+++
   12 |      7 | +++++--, ++++-++
   19 |      8 | -++++++-
   39 |     12 | +++++++++---
   40 |     13 | +++++++++---+, ++++++++-+++-
   45 |      9 | +++++++++
   97 |     20 | ++++++++++++++--+---, +++++++++++++-++++--, ++++++++++++-++++++-
  361 |     34 | ++++++++++++++++++++++++++-+++-+++


Extra resources


Proof that any number can be made: basically, by repeating ++-, you can obtain any even number. To obtain the odd numbers, just put a + at the end.
Another general way to obtain any number. For example, to generate 50, a way is to press + 50 times, and then press - 49 times.
Solution of the first 50 numbers.
Obligatory JSFiddle.


Scoring

This is code-golf. Shortest solution in bytes wins.
MATL, 43 29 bytes
E:&quot;@TFEqZ^!&quot;@Y'tQ**s]vGE=a?@.

This is memory- and time-inefficient. The online compiler can handle up to input 45 only.
Try it online!
Here's a modified version with all test cases up to 40 (it takes almost a minute in the online compiler).
Explanation
This tests all possible key-press sequences of each length, in order of increasing length, until a valid sequence is found.
E:       % Range [1 2 ... 2*N] where N is implicit input. The required sequence length is
         % less than 2*N, so this is enough
&quot;        % For each
  @      %   Push current value: length of sequence
  TFEq   %   Push array [1 -1]
  Z^     %   Cartesian power. Gives all possible sequences of 1, -1 of that length
  !      %   Transpose. Each sequence is now a row
  &quot;      %   For each sequence
    @    %     Push current sequence
    Y'   %     Run-length decoding: Pushes an array of values 1 and -1, and then an
         %     array of run-lengths
    tQ*  %     Duplicate, add 1, multiply. Gives twice the triangular number for each run
    *    %     Multiply element-wise by 1 or -1 to produce correct sign
    s    %     Sum of array. This is the number produced by the current sequence
  ]      %   End for
  v      %   Concatenate all numbers into an array
  GE=a   %   True if any of those numbers equals twice the input
  ?      %   If so
    @    %     Push current sequence length. This is the final result
    .    %     Break loop
         %   End if
         % End for
         % Implicit display