题目描述
Farmer Nhoj dropped Bessie in the middle of nowhere! At time t=0, Bessie is located at x=0 on an infinite number line. She frantically searches for an exit by moving left or right by 11 unit each second. However, there actually is no exit and after T seconds, Bessie is back at x=0, tired and resigned.
Farmer Nhoj tries to track Bessie but only knows how many times Bessie crosses x=0.5,1.5,2.5,⋯,(N−1).5, given by an array A0,A1,⋯,AN−1(1≤N≤105,1≤Ai≤106,∑Ai≤106). Bessie never reaches x>N nor x<0.
In particular, Bessie's route can be represented by a string of T=i=0∑N−1Ai Ls and Rs where the i-th character represents the direction Bessie moves in during the ith second. The number of direction changes is defined as the number of occurrences of LRs plus the number of occurrences of RLs.
Please help Farmer Nhoj find any route Bessie could have taken that is consistent with A and minimizes the number of directio