Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <vector>
- using namespace std;
- typedef long long ll;
- int n, k;
- int arr[100005];
- // dp[k_left] --> brojot na nacini taka sto imame iskoristeno k_left candies
- int dp[100005];
- const int MOD = 1e9 + 7;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin >> n >> k;
- for(int i = 0; i < n; i++) {
- cin >> arr[i];
- }
- memset(dp, 0, sizeof dp);
- dp[0] = 1;
- for(int i = 0; i < n; i++) {
- vector<int> prefix_sum(k + 1, 0);
- for(int candies = k; candies >= 0; candies--) {
- int x = dp[candies];
- int L = candies + 1;
- int R = candies + min(arr[i], k - candies);
- if(L <= R) {
- prefix_sum[L] += x;
- prefix_sum[L] %= MOD;
- if(R + 1 <= k) {
- prefix_sum[R + 1] -= x;
- prefix_sum[R + 1] += MOD;
- prefix_sum[R + 1] %= MOD;
- }
- }
- }
- int pref = 0;
- for(int j = 0; j <= k; j++) {
- pref += prefix_sum[j];
- pref %= MOD;
- dp[j] += pref;
- dp[j] %= MOD;
- }
- }
- cout << dp[k] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement