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 int long long
int n, d, t;
#define MAX 2000007
int arr[MAX], dp[MAX];
int cost(int l, int r){
int ans = 0;
if (arr[l] <= t) ans++;
int carry = arr[l] + 1;
for (int x = l+1; x <= r; x++){
int val = min(arr[x], carry);
if (val <= t) ans++;
carry = min(carry, arr[x]);
carry += 1;
}
return ans;
}
main(){
cin >> n >> d >> t;
for (int x = 0; x < n; x++) cin >> arr[x];
for (int x = 0; x < n; x++){
dp[x] = cost(0, x);
for (int y = 0; y < x; y++){
dp[x] = min(dp[x], dp[y] + cost(y+1, x));
}
}
cout << dp[n-1];
}
Compilation message (stderr)
prison.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
27 | main(){
| ^~~~
# | 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... |