Submission #1149748

#TimeUsernameProblemLanguageResultExecution timeMemory
1149748cpismylifeOwO수열 (APIO14_sequence)C++20
0 / 100
0 ms320 KiB
#include <bits/stdc++.h> using namespace std; const long long inf = -1e18; const long long mod = 1e9 + 7; const int MaxN = 1e3 + 5; int n, k; long long arr[MaxN]; void Inp() { cin >> n >> k; k++; for (int x = 1; x <= n; x++) { cin >> arr[x]; } } long long sum[MaxN]; pair<long long, int> F[MaxN][MaxN]; void Exc() { for (int x = 1; x <= n; x++) { sum[x] = sum[x - 1] + arr[x]; } F[0][0] = make_pair(0, 0); for (int x = 1; x <= n; x++) { F[0][x] = make_pair(inf, 0); } for (int x = 1; x <= k; x++) { for (int y = 0; y < x; y++) { F[x][y] = make_pair(inf, 0); } for (int y = x; y <= n; y++) { F[x][y] = make_pair(inf, 0); for (int z = x - 1; z < y; z++) { F[x][y] = max(F[x][y], make_pair(F[x - 1][z].first + (sum[y] - sum[z]) * sum[z], z)); } } } for (int x = 1; x <= k; x++) { for (int y = 1; y <= n; y++) { cout << F[x][y].second << " "; } cout << "\n"; } pair<long long, int> res = F[k][n]; cout << res.first << "\n"; int cur = k; while (res.second > 0) { cout << res.second << " "; cur--; res = F[cur][res.second]; } } int main() { //freopen("B.INP", "r", stdin); //freopen("B.OUT", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(nullptr); int test = 1; //cin >> test; for (int w = 1; w <= test; w++) { Inp(); Exc(); } 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...