답안 #1017513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017513 2024-07-09T08:35:04 Z vjudge1 Klasika (COCI20_klasika) C++17
0 / 110
2 ms 2512 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -