Guest User

Untitled

a guest
Jun 27th, 2020
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std ;
  3.  
  4. #define M 1000000007
  5. #define MM 998244353
  6. #define ll long long
  7. #define pb push_back
  8. #define mem0(a) memset(a,0,sizeof(a))
  9. #define mem1(a) memset(a,-1,sizeof(a))
  10. #define memf(a) memset(a,false,sizeof(a))
  11. #define all(v) v.begin(),v.end()
  12. #define sz(a) (ll)a.size()
  13. #define F first
  14. #define S second
  15. #define INF 2000000000000000000
  16. #define endl "\n"
  17. #define _time_ 1.0 * clock() / CLOCKS_PER_SEC
  18. #define popcount(x) __builtin_popcountll(x)
  19. #define pll pair<ll,ll>
  20. #define ld long double
  21.  
  22. const long double PI = acos(-1);
  23.  
  24. ll power(ll b,ll e,ll m)
  25. {
  26. if(e==0) return 1;
  27. if(e&1) return b*power(b*b%m,e/2,m)%m;
  28. return power(b*b%m,e/2,m);
  29. }
  30. ll power( ll b, ll e)
  31. {
  32. if(e==0) return 1;
  33. if(e&1) return b*power(b*b,e/2);
  34. return power(b*b,e/2);
  35. }
  36. template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
  37. template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
  38. template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
  39. {
  40. return os<<'('<<p.F<< ","<<p.S<<')';
  41. }
  42.  
  43. const int N=100005,K=102;
  44. ll dp[2][N];
  45. ll h[K],s[K],k[K];
  46. int _runtimeTerror_()
  47. {
  48. int n,x;
  49. cin>>n>>x;
  50. for(int i=1;i<=n;++i)
  51. cin>>h[i];
  52. for(int i=1;i<=n;++i)
  53. cin>>s[i];
  54. for(int i=1;i<=n;++i)
  55. cin>>k[i];
  56. for(int i=1;i<=n;++i)
  57. {
  58. for(int j=0;j<h[i];++j)
  59. {
  60. dp[i%2][j]=dp[(i-1)%2][j];
  61. deque<pll> dq;
  62. dq.push_back({j,dp[i%2][j]});
  63. for(int l=j+h[i];l<=x;l+=h[i])
  64. {
  65. ll y=dp[(i-1)%2][l]-s[i]*(l-j)/h[i];
  66. while(!dq.empty() && dq.back().S<=y)
  67. dq.pop_back();
  68. dq.push_back({l,y});
  69. while((l-dq.front().F)/h[i]>k[i])
  70. dq.pop_front();
  71. dp[i%2][l]=dq.front().S+(l-j)/h[i]*s[i];
  72. }
  73. }
  74. }
  75. cout<<dp[n%2][x];
  76. return 0;
  77. }
  78.  
  79. int main()
  80. {
  81. ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  82. #ifdef runSieve
  83. sieve();
  84. #endif
  85. #ifdef NCR
  86. initialize();
  87. #endif
  88. int TESTS=1;
  89. //cin>>TESTS;
  90. while(TESTS--)
  91. _runtimeTerror_();
  92. return 0;
  93. }
Add Comment
Please, Sign In to add comment