이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pairll pair<ll,ll>
#define lpairll pair<ll,pairll>
#define repp(i,a,b) for (ll i = a; i <= b; i++)
#define repz(i,a,b) for (ll i = a; i < b; i++)
#define repm(i,a,b) for (ll i = a; i >= b; i--)
#define fr first
#define sc second
#define x first
#define y second
#define mp make_pair
#define pb push_back
const ll N = 2e3+5, MOD = 1e9+7;
ll tc = 1, n, m, ar[N], br[N], dp[N][N];
string s, s1, s2, ye = "YA", no = "TIDAK";
void input(){
  cin >> n >> m;
  repp(i,1,n) cin >> ar[i];
}
ll rec(ll idx, ll rem){
  if (rem == 0) return 0;
  if (idx > n) return 0;
  if (dp[idx][rem] != -1) return dp[idx][rem];
  ll ret = rec(idx+1,rem), cur = 0 , maxi = 0;
  repp(i,idx,n){
    cur += ar[i];
    maxi = max(maxi,cur);
    if (cur < 0) cur = 0;
    ret = max(ret,maxi+rec(i+1,rem-1));
  }
  //cout << idx << " " << rem << " " << ret << endl;
  return dp[idx][rem] = ret;
}
void solve(){
  memset(dp,-1,sizeof(dp));
  cout << rec(1,m) << endl;
}
int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  //cin >> tc;
  while(tc--){
    input();
    solve();
  }
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |