# Workers Codechef Solution

Workers Codechef Solution: There are NN workers; each worker is of one of the following three types:

• translator translates some text from Chef’s language to another langague.
• An author writes some text in Chef’s language.
• An author-translator can both write a text in Chef’s language and translate it to another language.

Chef wants to have some text written and translated into some language (different from Chef’s language). Chef can’t do either of those tasks, but he can hire workers. For each ii (1≤i≤N1≤i≤N), if he hires the ii-th worker, he must pay that worker cici coins.

Help Chef find the minimum total number of coins he needs to pay to have a text written and translated. It is guaranteed that it is possible to write and translate a text.

### Input

• The first line of the input contains a single integer NN denoting the number of workers.
• The second line contins NN space-separated integers c1,c2,…,cNc1,c2,…,cN denoting the numbers of coins Chef has to pay each hired worker.
• The third line contains NN space-separated integers t1,t2,…,tNt1,t2,…,tN denoting the types of workers. For each valid ii, the ii-th worker is a translator if ti=1ti=1, an author if ti=2ti=2 or an author-translator if ti=3ti=3.

### Output

Print a single line containing one integer — the minimum number of coins Chef has to pay.

### Constraints

• 1≤N≤1,0001≤N≤1,000
• 1≤ci≤100,0001≤ci≤100,000 for each valid ii
• 1≤ti≤31≤ti≤3 for each valid ii

```5
1 3 4 6 8
1 2 1 2 3
```

```4
```

### Explanation

Chef can hire 2 workers: worker 1, who is a translator, and worker 2, who is an author. In total, he pays them 1+3=41+3=4 coins.

### Workers CodeChef Solution in JAVA

```import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n= sc.nextInt();
int Ci[] = new int[n];
int Ti[] = new int[n];
int wr = 100000,ar = 100000, wrar= 100000;
for(int i = 0; i<n; i++){
Ci[i] = sc.nextInt();
}
for(int i= 0; i<n; i++){
Ti[i] =sc.nextInt();
}
for(int i = 0; i<n; i++){
if(Ti[i]==1 && Ci[i] <= wr){
wr = Ci[i];
}else if(Ti[i] == 2 && Ci[i] <= ar){
ar = Ci[i];
}else if(Ti[i] == 3 && Ci[i] <= wrar){
wrar = Ci[i];
}
}
if(wr+ar < wrar){
System.out.println(wr+ar);
}else{
System.out.println(wrar);
}
}
}
```

### Workers CodeChef Solution in CPP

```#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
std::cin >> n;
int wage[n], skill[n];
for(int i = 0; i< n; i++)
{
std::cin >> wage[i];
}
for(int i = 0; i< n; i++)
{
std::cin >> skill[i];
}
long int min_wage1 = 100001;
long int min_wage2 = 100001;
long int min_wage3 = 100001;
for(int i = 0; i< n; i++)
{
if(skill[i] == 1 )
{
if(wage[i] < min_wage1)
min_wage1 = wage[i];
}
else if(skill[i] == 2 )
{
if(wage[i] < min_wage2)
min_wage2 = wage[i];
}
else
{
if(wage[i] < min_wage3)
min_wage3 = wage[i];
}
}
if(min_wage1+min_wage2<min_wage3)
{
std::cout << min_wage1+min_wage2 << std::endl;
}
else
{
std::cout << min_wage3 << std::endl;
}
return 0;
}
```

### Workers CodeChef Solution in Python

```n=int(input())
c=list(map(int,input().split()))
r=list(map(int,input().split()))
a=9999
b=9999
tr=9999
for  i in range(n):
if(r[i]==1):
a=min(a,c[i])
elif(r[i]==2):
b=min(b,c[i])
elif(r[i]==3):
tr=min(tr,c[i])
if(tr<(a+b)):
print(tr)
elif(tr>(a+b)):
print(a+b)
```

Disclaimer: The above Problem (Workers) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose.

Sharing Is Caring