Submission #987670

#TimeUsernameProblemLanguageResultExecution timeMemory
987670JahonaliXSplit the sequence (APIO14_sequence)C++17
0 / 100
2097 ms600 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, k, mx = 0, sm; cin >> n >> k; int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; if (i) a[i] += a[i - 1]; } vector<int> ans, vec; for (int i = 1; i <= k; ++i) vec.emplace_back(i); while (true) { sm = 0; for (int i = 0; i < k; ++i) { if (i) sm += (a[vec[i] - 1] - a[vec[i - 1] - 1]) * (a[n - 1] - a[vec[i] - 1]); else sm += a[vec[i] - 1] * (a[n - 1] - a[vec[i] - 1]); } if (sm > mx) ans = vec, mx = sm; vec[k - 1]++; for (int i = k - 1; i > 0; --i) if (vec[i] > n - k + i + 1) vec[i - 1]++, vec[i] = i + 1; if (vec[0] > n - k + 1) break; } cout << mx << '\n'; for (int i : ans) cout << i << ' '; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...