This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
int main()
{
  int n, L, R, k;
  cin >> n >> L >> R >> k;
  L--, R--;
  ll sm = 0;
  vector<int> v(n);
  for(int i = 0; i < n; i++)
    cin >> v[i];
  vector<int> f, s, t;
  int sf = L, ss = R - L + 1, st = n - R - 1;
  // cerr << "f = ";
  for(int i = 0; i < sf; i++)
    f.push_back(v[i]); // cerr << f[i] <<' ';
  // cerr << endl;
  
  for(int j = 0; j < ss; j++)
    sm += v[sf + j], s.push_back(v[sf + j]); 
  for(int i = 0; i < st; i++)
    t.push_back(v[ss + sf + i]);
  
  ll dp[2][ss + 1][1 + k];
  for(int i = 0; i <= ss; i++)
    for(int j = 0; j <= k; j++)
      dp[1][i][j] = dp[0][i][j] = 0;
  
  for(int i = 1; i <= sf; i++)
    for(int j = 1; j <= ss; j++)
      for(int c = 0; c <= k; c++)
	{
	  bool b = i & 1, nb = (i - 1) & 1;
	  dp[b][j][c] = max(dp[nb][j][c], dp[b][j - 1][c]);
	  int cost = sf + j - i;
	  // cerr << cost << ' ' << s[j - 1] - f[i - 1] << endl;
	  if(cost <= c)
	    dp[b][j][c] = max(dp[b][j][c], dp[nb][j - 1][c - cost] + (s[j - 1] - f[i - 1]));
	  // cerr << "dp[" << i << "][" << j << "][" << c << "] = " << dp[i][j][c] << endl;
	}
  // cerr << dp[sf & 1][ss][k] << endl;
  cout << sm - dp[sf & 1][ss][k] << endl;
  return 0;
}
| # | 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... |