Submission #844710

# Submission time Handle Problem Language Result Execution time Memory
844710 2023-09-05T17:41:42 Z vjudge1 Holding (COCI20_holding) C++17
110 / 110
188 ms 16964 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(n+5,vector<int>(k+5,INF));
  vector<vector<int>> ndp(n+5,vector<int>(k+5,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(n+5,vector<int>(k+5,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 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 1 ms 456 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 3 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 1 ms 456 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 3 ms 3164 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 35 ms 9132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 1 ms 456 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 3 ms 3164 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 35 ms 9132 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 34 ms 8968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 1 ms 456 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 3 ms 3164 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 35 ms 9132 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 34 ms 8968 KB Output is correct
20 Correct 5 ms 1116 KB Output is correct
21 Correct 8 ms 1552 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 44 ms 6492 KB Output is correct
24 Correct 5 ms 860 KB Output is correct
25 Correct 188 ms 16964 KB Output is correct