Advertisement
gkldiashvili

Untitled

Apr 20th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. long long n, k, d, t[3003], pt[3003], fp = 1e9;
  5. pair<long long, long long> dp[3003][3003];
  6.  
  7. int main() {
  8. ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  9. cin >> n >> k >> d;
  10. for(int i = 1; i <= n; ++i) {
  11. cin >> t[i];
  12. }
  13. for(int i = 1; i <= n; ++i) {
  14. pt[i] = pt[i - 1] + t[i];
  15. }
  16. for(int j = 1; j <= n; ++j) {
  17. for(int i = max(1, j - (int)k + 1); i <= j; ++i) {
  18. long long ti = i - 1;
  19. if(i == 1) ++ti;
  20. for(int gk = 1; gk <= min(ti, k); ++gk) {
  21. long long ov = max(t[j] - d, dp[i - 1][gk].second) + d, ck = j - i + 1;
  22. long long ljda = ov * ck - (pt[j] - pt[i - 1]);
  23. if(dp[j][ck].second == 0 || dp[j][ck].first > ljda + dp[i - 1][gk].first) {
  24. dp[j][ck] = make_pair(ljda + dp[i - 1][gk].first, ov);
  25. }
  26. }
  27. }
  28. }
  29. for(int i = 1; i <= k; ++i) {
  30. fp = min(fp, dp[n][i].first);
  31. }
  32. cout << fp << endl;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement