#APL+WIN, 33 bytes Prompts for vector of integers max first: +/,((1+⌈⌈/2⍟v)⍴2)⊤v←(↑v)+0,⍳-/v←⎕ [Try it online! Courtesy of Dyalog Classic][TIO-ji1vy7dh] [APL (Dyalog Classic)]: https://www.dyalog.com/ [TIO-ji1vy7dh]: https://tio.run/##SyzI0U2pTMzJT9dNzkksLs5M/v@ob6qvz6O2CcZcjzra0/5r6@toaBhqP@rpACJ9o0e988s0H/VuMdJ81LWkDKhM41HbxDJNbQOdR72bdfVBIkAD/gO1/k/jMlcwAQA "APL (Dyalog Classic) – Try It Online"