結果

問題 No.1117 数列分割
ユーザー ei1333333ei1333333
提出日時 2020-07-17 21:44:38
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 708 bytes
コンパイル時間 2,879 ms
コンパイル使用メモリ 196,076 KB
最終ジャッジ日時 2025-01-11 22:31:12
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;
const int64 infll = (1LL << 62) - 1;

int main() {
  int N, K, M;
  cin >> N >> K >> M;
  vector< int > A(N);
  for(auto &a : A) cin >> a;
  vector< int64 > S(N + 1);
  for(int i = 1; i <= N; i++) S[i] = S[i - 1] + A[i - 1];
  auto dp = vector< int64 >(N + 1, -infll);
  dp[0] = 0;
  for(int i = 0; i < K; i++) {
    auto dp2 = vector< int64 >(N + 1, -infll);
    int64 latte = -infll, malta = -infll;
    for(int j = 1; j <= N; j++) {
      latte = max(latte, dp[j - 1] - S[j - 1]);
      malta = max(malta, dp[j - 1] + S[j - 1]);
      dp2[j] = max(latte + S[j], malta - S[j]);
    }
    dp.swap(dp2);
  }
  cout << dp[N] << "\n";
}
0