➤ Problem Link : PIGBANK
👉 Hint : edit please
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; #define ll long long int pair<int,int> arr[500]; ll dp[10001]; int main() { int t; cin>>t; while(t--) { int e,f,n,p,w; cin>>e>>f; cin>>n; for(int i=1;i<=f;i++) dp[i]=INT_MAX; for(int i=0;i<n;i++) { cin>>p>>w; arr[i].first=p; arr[i].second=w; } dp[0]=0; for(int i=1;i<=f-e;i++) { for(int j=0;j<n;j++) if(i>=arr[j].second) dp[i]=min(dp[i],dp[i-arr[j].second]+arr[j].first); } if(dp[f-e]>=INT_MAX) cout<<"This is impossible."<<endl; else cout<<"The minimum amount of money in the piggy-bank is "<<dp[f-e]<<"."<<endl; } }
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!!