Submission #1017738

# Submission time Handle Problem Language Result Execution time Memory
1017738 2024-07-09T09:49:24 Z vjudge1 Holding (COCI20_holding) C++17
55 / 110
14 ms 4656 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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 2 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 2 ms 1628 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 14 ms 4656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 2 ms 1628 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 14 ms 4656 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 2 ms 1628 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 14 ms 4656 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Halted 0 ms 0 KB -