fork download
  1. n,m = [int(_) for _ in input().split()]
  2. pole = [int(_) for _ in input().split()]
  3. maxim = 0
  4. for i in range(0,n-2):
  5. for j in range(i+1+m,n-1):
  6. for k in range(j+1+m, n):
  7. if (pole[i]+pole[j]+pole[k] > maxim):
  8. maxim = pole[i]+pole[j]+pole[k]
  9. print(maxim)
  10.  
  11. maxim = 0
  12. for j in range(1+m,n-1-m):
  13. b = pole[j]
  14. a = pole[0]
  15. for i in range(1, j-m):
  16. if (pole[i] > a):
  17. a = pole[i]
  18. c = pole[n-1]
  19. for k in range(j+m+1, n-1):
  20. if (pole[k] > c):
  21. c = pole[k]
  22. if (a+b+c > maxim):
  23. maxim = a+b+c
  24. print(maxim)
  25.  
Success #stdin #stdout 0.03s 27704KB
stdin
10 1
4 1 7 8 3 6 10 10 7 3
8 2
4 2 3 8 1 5 4 2
stdout
25
25