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 = @[0] & 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] for shikiri in 1..m: for i in 1..n: # shikiriが偶数:iより前に偶数枚の仕切りが入っているので、a[i]は加算する # shikiriが奇数:iより前に偶数枚の仕切りが入っているので、a[i]は減算する if shikiri.mod(2)==0: if dp[shikiri-1][i-1]+a[i] > dp[shikiri][i-1]+a[i]: frm[shikiri][i]=true dp[shikiri][i] = max(dp[shikiri-1][i-1],dp[shikiri][i-1])+a[i] else: if dp[shikiri-1][i-1]-a[i] > dp[shikiri][i-1]-a[i]: frm[shikiri][i]=true dp[shikiri][i] = max(dp[shikiri-1][i-1],dp[shikiri][i-1])-a[i] #echo dp.join("\n") 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 x!=0: if frm[y][x]: ans.add(x-1) y = y-1 x = x-1 else: x = x-1 for i in 0..i: echo ans[i] else: echo n solve()