Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
65
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. const unsigned int mod=1000000007;
  5.  
  6. unsigned int dp[10010][2];
  7. long long sum[10010];
  8.  
  9. long long dist(unsigned int lo,unsigned int hi)
  10. {
  11. return sum[hi-1]-sum[lo-1];
  12. }
  13.  
  14. int main()
  15. {
  16. ios_base::sync_with_stdio(false);
  17. cin.tie(0);
  18. cout.tie(0);
  19. unsigned int in,d,lo,hi,n,i,j;
  20. cin>>n>>d;
  21. for(i=1;i<=n;i++)
  22. {
  23. cin>>in;
  24. sum[i]=sum[i-1];
  25. sum[i]+=in;
  26. }
  27. dp[1][0]=1;
  28. long long maxdist=dist(1,2);
  29. for(hi=3;hi<=n+1;hi++)
  30. {
  31. for(lo=1;lo<hi;lo++)
  32. {
  33. dp[lo][hi%2]=0;
  34. if(dist(lo,hi)<=d)
  35. {
  36. maxdist=max(maxdist,dist(lo,hi));
  37. if(lo-1>0&&dist(lo-1,hi)<=d)
  38. {
  39. dp[lo][hi%2]+=dp[lo-1][hi%2];
  40.  
  41. }
  42. if(hi-1>lo&&dist(lo,hi-1)<=d)
  43. {
  44. dp[lo][hi%2]+=dp[lo][(hi-1)%2];
  45.  
  46. }
  47. if(lo-1>0&&dist(lo-1,hi-1)<=d)
  48. {
  49. dp[lo][hi%2]+=dp[lo-1][(hi-1)%2];
  50. }
  51. dp[lo][hi%2]%=mod;
  52. }
  53. }
  54. }
  55. cout<<maxdist<<" "<<dp[n][(n+1)%2]%mod;
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement