Created
May 10, 2020 15:45
-
-
Save cypher-nullbyte/e1db14a8e938506b878c321f338a1602 to your computer and use it in GitHub Desktop.
Vpropel VIT | POD | 10/05/2020 | Eat chocolates | 10
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> | |
using namespace std; | |
void Sort(int arr[],int brnd[],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]); | |
brnd[i]=brnd[i]+brnd[min_idx]-(brnd[min_idx]=brnd[i]); | |
} | |
} | |
} | |
int brandchk(int arr[],int n,int val) | |
{ | |
int count=0; | |
for(int i=0;i<n;i++) | |
{ | |
if(arr[i]==val) | |
count++; | |
} | |
return count; | |
} | |
int main() | |
{ | |
int n; | |
scanf("%d",&n); | |
int cost[n]; | |
int brand[n]; | |
for(int i=0;i<n;i++) | |
scanf("%d",&cost[i]); | |
for(int i=0;i<n;i++) | |
scanf("%d",&brand[i]); | |
int limit,m; | |
scanf("%d",&m); | |
scanf("%d",&limit); | |
Sort(cost,brand,n); | |
int brndck[n]={0}; | |
int tot=0; | |
//int brandcnt=0; | |
int chococnt=0; | |
for(int i=n-1;i>-1;i--) | |
{ | |
if(brandchk(brndck,n,brand[i])<limit) | |
{ | |
brndck[i]=brand[i]; | |
if(chococnt<m) | |
{ | |
chococnt++; | |
tot+=cost[i]; | |
} | |
} | |
} | |
printf("%d",tot); | |
return 0; | |
} |
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> | |
using namespace std; | |
void Sort(int arr[],int brnd[],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]); | |
brnd[i]=brnd[i]+brnd[min_idx]-(brnd[min_idx]=brnd[i]); | |
} | |
} | |
} | |
int brandchk(int arr[],int n,int val) | |
{ | |
int count=0; | |
for(int i=0;i<n;i++) | |
{ | |
if(arr[i]==val) | |
count++; | |
} | |
return count; | |
} | |
int main() | |
{ | |
int n; | |
cin>>n; | |
int cost[n]; | |
int brand[n]; | |
for(int i=0;i<n;i++) | |
cin>>cost[i]; | |
for(int i=0;i<n;i++) | |
cin>>brand[i]; | |
int limit,m; | |
cin>>m; | |
cin>>limit; | |
Sort(cost,brand,n); | |
int brndck[n]={0}; | |
int tot=0; | |
//int brandcnt=0; | |
int chococnt=0; | |
for(int i=n-1;i>-1;i--) | |
{ | |
if(brandchk(brndck,n,brand[i])<limit) | |
{ | |
brndck[i]=brand[i]; | |
if(chococnt<m) | |
{ | |
chococnt++; | |
tot+=cost[i]; | |
} | |
} | |
} | |
cout<<tot; | |
return 0; | |
} |
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
Eat chocolates | |
Ramesh wants to buy some chocolates. But there are some constraints that she needs to follow. | |
She can only buy “m” chocolates and can buy the chocolates of the same brand only up to a certain limit. | |
Given the cost and brand of the chocolates find the maximum cost at which she can buy the chocolates | |
Example1:- | |
Cost of chocolates:- [5,4,3,2,1] | |
Cost[i] represents the cost of ith chocolate | |
Brand of the chocolates :-[1,1,2,2,3] | |
Here brand[i] represents the brand of its chocolates 1,2,3 etc. represents brand | |
No.of Chocolates to be bought-3 | |
Brand Limit -1 | |
In this case she can select only one chocolate per brand as the brand limit is one | |
So the combination which leads to maximum cost is 5+3+1=9 | |
Each of the brand has been used lesser than or equal to the brand limit | |
Example2:- | |
Cost of chocolates:-[5,4,3,2,1] | |
Brand of chocolates:-[1,3,3,3,2] | |
No of chocolates to be bought-3 | |
Brand limit -2 | |
In this she can choose upto two chocolates of the same brand | |
So in this case the combination 5+4+3 leads to maximum cost | |
Constraints:- | |
1<=brand[i]<=5(There are totally 5 brands) | |
Input format:- | |
n-Total number of chocolates in shop | |
Next n lines –Cost of chocolates | |
Next n lines –Brand of chocolates | |
Number of chocolates to be bought(m) | |
Brand Limit | |
Output:- | |
Maximum cost |
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
Rank Registration Number Name | |
1 19BAI1035 S.O.NARENDRAN | |
2 19BCE1492 P.K. AMUDHINI | |
3 19BCE1449 CHANDHRU K | |
4 19BCE1401 S VAIBHAVE | |
5 19BCE1717 MAKESH SRINIVASAN | |
6 19BCE2642 GUNJAN RAJ TIWARI | |
7 19BCE1540 T DAMIAN LOURDES | |
8 18BCE2446 ASHISH POUDEL | |
9 19BLC1055 SUNIL KUMAR GV | |
10 19BCI0016 CHIRANJEET SINGH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment