結果
問題 |
No.2139 K Consecutive Sushi
|
ユーザー |
![]() |
提出日時 | 2022-12-16 20:50:26 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 596 bytes |
コンパイル時間 | 3,070 ms |
コンパイル使用メモリ | 250,240 KB |
実行使用メモリ | 814,848 KB |
最終ジャッジ日時 | 2024-11-16 01:49:31 |
合計ジャッジ時間 | 30,368 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 3 WA * 11 MLE * 17 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll n,k; cin>>n>>k; vector<ll> a(n); for(auto& x:a)cin>>x; vector<vector<ll>> dp(n+1,vector<ll>(k,0)); for(int i=0;i<n;i++){ for(int j=0;j<=min((ll)i,k-1);j++){ if(j==k-1){ dp[i+1][0]=max(dp[i+1][0],dp[i][j]); }else{ dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+a[i]); dp[i+1][j]=max(dp[i+1][j],dp[i][j]); } } } ll ans=0; for(int i=0;i<k;i++)ans=max(ans,dp[n][i]); cout<<ans<<endl; }