Last active
May 6, 2020 18:30
-
-
Save cypher-nullbyte/7928458f142219339583cf61c44c48d7 to your computer and use it in GitHub Desktop.
Vpropel VIT | POD | 06/05/2020 | No Change
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
void Sort(int arr[],int n) | |
{ | |
for(int i=0;i<n-1;i++) | |
{ | |
int min_idx=i; | |
for(int j=i+1;j<n;j++) | |
{ | |
if(arr[j]<arr[min_idx]) | |
min_idx=j; | |
} | |
if(min_idx!=i) | |
{ | |
arr[i]=arr[i]+arr[min_idx]-(arr[min_idx]=arr[i]); | |
} | |
} | |
} | |
int MinDenom(int arr[],int amt,int n) | |
{ | |
int dno=0; | |
int amt2=amt; | |
for(int i=n-1;i>=0;i--) | |
{ | |
if(amt2>=arr[i]) | |
{ | |
int counter=amt2/arr[i]; | |
amt2=amt2-counter*arr[i]; | |
dno+=counter; | |
} | |
} | |
if(amt2==0) | |
return dno; | |
else | |
return -1; | |
} | |
int main() | |
{ | |
int amt; | |
scanf("%d",&amt); | |
int n; | |
scanf("%d",&n); | |
int arr[n]; | |
for(int i=0;i<n;i++) | |
scanf("%d",&arr[i]); | |
Sort(arr,n); | |
printf("%d",MinDenom(arr,amt,n)); | |
return 0; | |
} | |
// ### Thank YOu :) | |
// @cs_jawanda | |
// .Chiranjeet Singh Jawanda. | |
// VIT VELLORE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
void Sort(int arr[],int n) | |
{ | |
for(int i=0;i<n-1;i++) | |
{ | |
int min_idx=i; | |
for(int j=i+1;j<n;j++) | |
{ | |
if(arr[j]<arr[min_idx]) | |
min_idx=j; | |
} | |
if(min_idx!=i) | |
{ | |
arr[i]=arr[i]+arr[min_idx]-(arr[min_idx]=arr[i]); | |
} | |
} | |
} | |
int MinDenom(int arr[],int &amt,int n) | |
{ | |
int dno=0; | |
int amt2=amt; | |
for(int i=n-1;i>=0;i--) | |
{ | |
if(amt2>=arr[i]) | |
{ | |
int counter=amt2/arr[i]; | |
amt2=amt2-counter*arr[i]; | |
dno+=counter; | |
} | |
} | |
if(amt2==0) | |
return dno; | |
else | |
return -1; | |
} | |
int main() | |
{ | |
int amt; | |
std::cin>>amt; | |
int n; | |
std::cin>>n; | |
int arr[n]; | |
for(int i=0;i<n;i++) | |
std::cin>>arr[i]; | |
Sort(arr,n); | |
std::cout<<MinDenom(arr,amt,n); | |
return 0; | |
} | |
// ### Thank YOu :) | |
// @cs_jawanda | |
// .Chiranjeet Singh Jawanda. | |
// VIT VELLORE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Wait a little bit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
amt=int(input()) | |
n=int(input()) | |
arr=[]; | |
for i in range(n): | |
arr.append(int(input())) | |
arr.sort() | |
dno=0 | |
i=n-1; | |
while i>=0: | |
if(amt>=arr[i]): | |
counter=amt//arr[i] | |
amt=amt-counter*arr[i] | |
dno+=counter | |
i-=1 | |
if(amt==0): | |
print(dno) | |
else: | |
print(-1) | |
#// ### Thank YOu :) | |
#// @cs_jawanda | |
#// .Chiranjeet Singh Jawanda. | |
#// VIT VELLORE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
No Change | |
Vikram’s mom gave him a certain amount of money and asked him to get change for the money in coins. | |
She also told the denominations of coin she wanted and also told the total number of coins must be minimum. | |
If that amount of money cannot be made up by any combination of the coins, print -1. | |
Example1:- | |
Let the Amount – 11 | |
Let the Denominations be = [1, 2, 5] | |
Output:- 3 | |
Explanation:- 11 = 5+5+1 (This is the minimum possible combination) | |
Example2:- | |
Let the amount:- 3 | |
Let the denominations be:- [2] | |
Output:- -1 | |
Explanation:- 3 cannot be made up by any combination of the coins of denomination 2 | |
Input format:- | |
Total Amount | |
Number of denomination-n | |
Next n lines-denomination | |
Output format:- | |
Minimum number of coins. | |
Constraints:- | |
1<=denominations[i]<=30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment