➤ Problem Link : 734C. Anton and Making Potions
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; #define ll long long int int main() { ll n,m,k,x,s; cin>>n>>m>>k; cin>>x>>s; ll first[m],fcost[m]; for(ll i=0;i<m;i++) cin>>first[i]; for(ll i=0;i<m;i++) cin>>fcost[i]; ll second[k],scost[k]; for(ll i=0;i<k;i++) cin>>second[i]; for(ll i=0;i<k;i++) cin>>scost[i]; ll ans = n*x; ll low,high,mid; ll cost; for(ll i=0;i<m;i++) { cost=s-fcost[i]; if(cost<0) continue; ll rem; if(cost<scost[0]) rem=n; else { low=0,high=k-1; while(low<high) { mid=low+(high-low+1)/2; if(scost[mid]<=cost) low=mid; else high=mid-1; } rem=n-second[high]; if(rem<0) { ans=0; break; } } ans=min(ans,rem*first[i]); } for(ll i=0;i<k;i++) { cost=s-scost[i]; if(cost<0) continue; ll rem=n-second[i]; if(rem<=0) { ans=0; break; } ans=min(ans,rem*x); } cout<<ans; }
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!