Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std ;
- #define M 1000000007
- #define MM 998244353
- #define ll long long
- #define pb push_back
- #define mem0(a) memset(a,0,sizeof(a))
- #define mem1(a) memset(a,-1,sizeof(a))
- #define memf(a) memset(a,false,sizeof(a))
- #define all(v) v.begin(),v.end()
- #define sz(a) (ll)a.size()
- #define F first
- #define S second
- #define INF 2000000000000000000
- #define endl "\n"
- #define _time_ 1.0 * clock() / CLOCKS_PER_SEC
- #define popcount(x) __builtin_popcountll(x)
- #define pll pair<ll,ll>
- #define ld long double
- const long double PI = acos(-1);
- ll power(ll b,ll e,ll m)
- {
- if(e==0) return 1;
- if(e&1) return b*power(b*b%m,e/2,m)%m;
- return power(b*b%m,e/2,m);
- }
- ll power( ll b, ll e)
- {
- if(e==0) return 1;
- if(e&1) return b*power(b*b,e/2);
- return power(b*b,e/2);
- }
- template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
- template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
- template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
- {
- return os<<'('<<p.F<< ","<<p.S<<')';
- }
- const int N=100005,K=102;
- ll dp[2][N];
- ll h[K],s[K],k[K];
- int _runtimeTerror_()
- {
- int n,x;
- cin>>n>>x;
- for(int i=1;i<=n;++i)
- cin>>h[i];
- for(int i=1;i<=n;++i)
- cin>>s[i];
- for(int i=1;i<=n;++i)
- cin>>k[i];
- for(int i=1;i<=n;++i)
- {
- for(int j=0;j<h[i];++j)
- {
- dp[i%2][j]=dp[(i-1)%2][j];
- deque<pll> dq;
- dq.push_back({j,dp[i%2][j]});
- for(int l=j+h[i];l<=x;l+=h[i])
- {
- ll y=dp[(i-1)%2][l]-s[i]*(l-j)/h[i];
- while(!dq.empty() && dq.back().S<=y)
- dq.pop_back();
- dq.push_back({l,y});
- while((l-dq.front().F)/h[i]>k[i])
- dq.pop_front();
- dp[i%2][l]=dq.front().S+(l-j)/h[i]*s[i];
- }
- }
- }
- cout<<dp[n%2][x];
- return 0;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
- #ifdef runSieve
- sieve();
- #endif
- #ifdef NCR
- initialize();
- #endif
- int TESTS=1;
- //cin>>TESTS;
- while(TESTS--)
- _runtimeTerror_();
- return 0;
- }
Add Comment
Please, Sign In to add comment