Submission #844709

# Submission time Handle Problem Language Result Execution time Memory
844709 2023-09-05T17:40:32 Z vjudge1 Holding (COCI20_holding) C++17
0 / 110
1 ms 344 KB
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define endl "\n" 
#define int long long
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

const int INF = 1e18;

void solve()
{
  int n,l,r,k;
  cin >> n >> l >> r >> k;
  vector<vector<int>> dp(r-l+5,vector<int>(k+1,INF));
  vector<vector<int>> ndp(r-l+5,vector<int>(k+1,INF));
  dp[0][0]=0;

  int ar[n+1];
  for(int i=1;i<=n;i++) cin >> ar[i];
  for(int i=1;i<=n;i++)
  {
    for(int j=0;j<=n;j++)
    {
      for(int z=0;z<=k;z++)
      {
        if(dp[j][z]==INF) continue;
        // aldim
        if(j+1<=r-l+1 && z+abs(i-(l+j)) <= k)
         ndp[j+1][z+abs(i-(l+j))] = min( ndp[j+1][z+abs(i-(l+j))] , dp[j][z] + ar[i]);
        // almadim 
         ndp[j][z] = min(ndp[j][z] , dp[j][z]);
      }
    }
    dp=ndp;
    ndp.assign(r-l+5,vector<int>(k+1,INF));
  }
  
  int ans=INF;
  for(int i=0;i<=k;i++)
    ans=min(ans,dp[r-l+1][i]);
  
  cout << ans << endl;
}

int32_t main(){

  cin.tie(0); ios::sync_with_stdio(0);
  
  int t=1;//cin >> t;
  while(t--) solve();

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 1 ms 344 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 1 ms 344 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 1 ms 344 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 1 ms 344 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -