結果

問題 No.2889 Rusk
ユーザー hongrockhongrock
提出日時 2024-09-13 21:42:31
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 923 bytes
コンパイル時間 2,085 ms
コンパイル使用メモリ 200,316 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2024-09-13 21:42:42
合計ジャッジ時間 5,916 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 52
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define pb emplace_back
#define mp make_pair
 
using ll = long long;
using pii = pair<int,int>;
 
constexpr int mod = 998244353;
constexpr int inf = 0x3f3f3f3f;
constexpr int N = 2e5 + 10;

int n, a[N], b[N], c[N];
ll dp[N][6];

void _main(){
  cin >> n;
  for(int i=1; i<=n; ++i) cin >> a[i];
  for(int i=1; i<=n; ++i) cin >> b[i];
  for(int i=1; i<=n; ++i) cin >> c[i];
  for(int i=1; i<=n; ++i){
    dp[i][0] = dp[i-1][0] + a[i];
    dp[i][1] = max(dp[i-1][0], dp[i-1][1]) + b[i];
    dp[i][2] = max(dp[i-1][0], max(dp[i-1][1], dp[i-1][2])) + c[i];
    dp[i][3] = max(dp[i-1][3], dp[i-1][1]) + a[i];
    dp[i][4] = max(dp[i-1][4], max(dp[i-1][3], dp[i-1][2])) + b[i];
    dp[i][5] = *max_element(dp[i-1], dp[i-1] + 6) + a[i];
  }
  cout << *max_element(dp[n], dp[n] + 6) << '\n';
}

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  _main();
  return 0;
}
0