제출 #90089

#제출 시각아이디문제언어결과실행 시간메모리
90089mra2322001수열 (APIO14_sequence)C++14
50 / 100
2064 ms39764 KiB
#include <bits/stdc++.h> #define f0(i, n) for(int i(0); i < (n); i++) #define f1(i, n) for(int i(1); i <= n; i++) using namespace std; typedef long long ll; const int N = 100002; int n, a[N], k, pos[N][202]; ll f[N][202], t[N]; int main(){ ios_base::sync_with_stdio(0); cin >> n >> k; f1(i, n) cin >> a[i]; f1(i, n) t[i] = t[i - 1] + a[i]; f1(i, n){ f[i][0] = (t[i])*1ll*(t[n] - t[i]); for(int j = 1; j < i; j++){ if(j > k) break; for(int x = i - 1; x >= 1; x--){ /// f[x][j - 1] if(x > j - 1){ ll cur = f[x][j - 1] + (t[i] - t[x])*(t[n] - t[i]); f[i][j] = max(f[i][j], cur); if(cur == f[i][j]){ pos[i][j] = x; } } else break; } } } cout << f[n][k] << endl; int now = pos[n][k]; while(k--){ cout << now << " "; now = pos[now][k]; } }
#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...