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;
#define lg long long
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const lg N = 505;
lg n, d, tim;
lg dp[2][N][N];
lg t[N];
int main()
{
fastio;
cin >> n >> d >> tim;
for(int i = 1; i <= n; i++)
{
cin >> t[i];
}
d = min(n, d);
t[0] = 1e18;
memset(dp, 0x3f, sizeof(dp));
dp[0][0][d] = 0;
for(int i = 1; i <= n; i++)
{
for(int j = 0; j <= d; j++)
{
for(int k = 0; k < i; k++) dp[i&1][k][j] = 3e9;
}
for(int j = 0; j <= d; j++)
{
lg mnm = t[i];
for(int k = i-1; k >= 0; k--)
{
mnm = min(mnm, t[k]+i-k);
dp[i&1][i][j] = min(dp[(i-1)&1][k][j+1]+(t[i] <= tim), dp[i&1][i][j]);
dp[i&1][k][j] = min(dp[(i-1)&1][k][j]+(mnm <= tim), dp[i&1][k][j]);
}
}
}
lg ans = n+1;
for(int i = 0; i <= n; i++)
{
for(int j = 0; j <= d; j++)
{
ans = min(ans, dp[n&1][i][j]);
}
}
cout << ans << '\n';
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |