Greedy_algorithm Indian coin change problem

 #include<bits/stdc++.h>

using namespace std;
#define shailesh ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define rep(i, a, b) for(int i=a; i<b; i++)
#define ff first
#define ss second



int main(){
   shailesh

   int n;
   cin>>n;
   vi a(n);



   rep(i, 0, n){
       cin>>a[i];
   }

   int x;
   cin>>x;

   sort(a.begin(), a.end(), greater<int>());

   int ans=0;

   rep(i, 0, n)
   {
       ans+=x/a[i];
       x-=x/a[i]*a[i];
   }

   cout<<ans<<endl;

   



return 0;
}


// input
10 1 2 5 10 20 50 100 200 500 2000 350

// output
3






Comments

Popular posts from this blog

priority_queue

Alignment in css

Queue data structure in c++