#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
#define int long long int
const int N = 1e5 + 10;
const int md = 1e9 + 7;
const int INF = 1e18;
int32_t main(int32_t argc, char *argv[]) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;
  // cin >> T;
  while (T--) {
    int n, k;
    cin >> n >> k; k++;
    vector<int> a(n + 1), pref(n + 1);
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      pref[i] = pref[i - 1] + a[i];
    }
    vector<vector<pair<int, int>>> sm(n + 1, vector<pair<int, int>> (n + 1));
    for (int i = 1; i <= n; i++) {
      sm[i][i].first = a[i];
      for (int j = i + 1; j <= n; j++) {
        for (int l = i; l < j; l++) {
          if (sm[i][j].first < (pref[l] - pref[i - 1]) * (pref[j] - pref[l])) {
            sm[i][j].first = (pref[l] - pref[i - 1]) * (pref[j] - pref[l]);
            sm[i][j].second = l;
          }
        }
      }
    }
    vector<vector<int>> dp(n + 1, vector<int> (k + 1));
    for (int q = 2; q <= k; q++) {
      for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
          if (!((q - 2) == 0 && (i - 1) >= 1) && (i - 1) >= (q - 2)) {
            dp[j][q] = max(dp[j][q], dp[i - 1][q - 2] + sm[i][j].first + (pref[i - 1] * (pref[j] - pref[i - 1])));
          }
        }
      }
    }
    cout << dp[n][k] << '\n';
    vector<int> ans;
    int i = n, q = k;
    while (q > 1 || (int) ans.size() < (k - 1)) {
      for (int j = (i - 1); j >= 1; j--) {
        if (!((q - 2) == 0 && (j - 1) >= 1) && (j - 1) >= (q - 2)) {
          if (dp[i][q] == (dp[j - 1][q - 2] + sm[j][i].first + (pref[j - 1] * (pref[i] - pref[j - 1])))) {
            ans.push_back(sm[j][i].second);
            ans.push_back(j - 1);
            i = j - 1;
            q -= 2;
            break;
          }
        }
      }
    }
    sort(ans.begin(), ans.end());
    for (int i = (ans[0] == 0 ? 1 : 0); i < (int) ans.size(); i++)
      cout << ans[i] << " ";
    cout << '\n';
  }
  return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |