import times, strutils, sequtils, math, algorithm, tables, sets, lists, intsets import critbits, future, strformat, deques template `max=`(x,y) = x = max(x,y) template `min=`(x,y) = x = min(x,y) template `mod=`(x,y) = x = x mod y template scan2 = (scan(), scan()) template scan3 = (scan(), scan()) let read* = iterator: string {.closure.} = while true: (for s in stdin.readLine.split: yield s) proc scan(): int = read().parseInt proc scanf(): float = read().parseFloat proc toInt(c:char): int = return int(c) - int('0') proc solve()= var n = scan() m = scan() a = newseqwith(n,scan()) dp = newseqwith(m+1,newseqwith(n+1,0)) frm = newseqwith(m+1,newseqwith(n+1,false)) for i in 1..n: dp[0][i] = dp[0][i-1]+a[i-1] for j in 1..m: for i in 1..n: # jが偶数:iより前に偶数枚の仕切りが入っているので、a[i]は加算する # jが奇数:iより前に偶数枚の仕切りが入っているので、a[i]は減算する if j.mod(2)==0: if dp[j-1][i-1] >= dp[j][i-1]+a[i-1]: frm[j][i]=true # 直前に仕切りがあったほうがいいフラグ dp[j][i] = max(dp[j-1][i-1]+a[i-1],dp[j][i-1]+a[i-1]) else: if dp[j-1][i-1] >= dp[j][i-1]-a[i-1]: frm[j][i]=true # 直前に仕切りがあったほうがいいフラグ dp[j][i] = max(dp[j-1][i-1]-a[i-1],dp[j][i-1]-a[i-1]) var maxIdx = -1 maxV = -int.high.div(4) #echo dp.join("\n") #echo frm.join("\n") for i in 0..m: if dp[i][^1]>maxV: maxV = dp[i][^1] maxIdx = i var y = maxIdx x = n ans = newseq[int]() while (y,x) != (0,0): if frm[y][x]: ans.add(x-1) y = y-1 x = x-1 else: x = x-1 if ans.len>0: echo ans.sorted.join("\n") else: for i in 0..