0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AtCoder Beginner Contest 128 D - equeue

Last updated at Posted at 2019-08-08

AtCoder Beginner Contest 128 D - equeue

import math
 
 
n, k = list(map(int, input().split()))
que = list(map(int, input().split()))
 
ans = 0
max_pop_cnt = min(n, k)
for pop_cnt in range(max_pop_cnt+1):
#  pop_cnt+1にしないと、pop_cntが0の場合は消えてしまう。
    for right in range(pop_cnt+1):
        for push_cnt in range((k - pop_cnt)+1):
            ans = max(ans, sum(sorted(que[:pop_cnt-right] + list(reversed(que))[:right])[push_cnt:]))
# reverseにした方がいい。-1で後ろからスライスをとると、0の場合に全部になってしまう。
print(ans)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?