- 2
whats teh problem??
Problem Statement In recent days, different types of disease-causing viruses are spreading rapidly. A group of doctors compiled a list of 26 viruses and gave them names from A to Z, and luckily they created a universal vaccine for all disease-causing viruses. But there is one issue if a person is treated again with the vaccine. The same virus will infect him. Doctors can treat exactly K numbers of patients in one go. You have to find the maximum number of patients that can be treated. my soln in comments
3 Réponses
0
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
// A function to implement bubble sort
void bubbleSort(int arr[], int n)
{
int i, j;
for (i = 0; i < n-1; i++)
// Last i elements are already in place
for (j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])
swap(&arr[j], &arr[j+1]);
}
int main() {
int m,n;
cin>>n>>m;
int x,y,z;
cin>>x>>y>>z;
int a[x],b[y],c[z];
for(int i=0 ;i<x ;i++)
cin>>a[i];
for(int i=0 ;i<y ;i++)
cin>>b[i];
for(int i=0 ;i<x ;i++)
cin>>c[i];
bubbleSort(a,x);
bubbleSort(b,y);
bubbleSort(c,z);
int cost=0,j=x-1,k=y-1,l=z-1;
for(int i=1 ; i<=n ;i++)
{
if(l<0)
cost+=a[j--];
else if(j>=0){
if(a[j]>=c[l])
{
cost+=a[j];
j--;
}
else {
cost+=c[l--];
}
}
else cost+=c[l--];
}
for(int i=1 ; i<=m ;i++)
{
if(l<0)
cost+=b[k--];
else if(k>=0){
if(b[k]>=c[l])
{
cost+=b[k];
k--;
}
else {
cost+=c[l--];
}
}
else cost+=c[l--];
}
cout<<cost;
return 0;
}
0
still 3 tests are getting failed