Can anyone HELP me out with this problem-CHPINTU

here is my code-

#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    int N,M,T,i,j;
    cin>> T;
    while(T--)
    {
    int price =0,min = 100000;
    cin >> N >> M;
    
    int f[N],p[N];
    for(i=0;i<N;i++)
    cin >> f[i];
    for(i=0;i<N;i++)
    cin>>p[i];
    
    
    for(i=1;i<=M;i++)
    {
        price =0;
        for(j=0;j<N;j++)
        {
            if(f[j]==i)
            price = price + p[j];
        }
        if(price!=0 && price<=min)
        min = price;
        
    } 
    
    cout<<min<<endl;

    
    }
    
}```

Value of Pi can even be zero, so in your case min value will never be 0.

1 Like

according to the question, price equal to zero is not considered

try this to make process fast
for(int k=0;k<n;k++)
sum[f[k]-1]+=cost[k];

int min=Integer.MAX_VALUE;
for(int k=0;k<n;k++)
{
if(min>sum[f[k]-1])
min=sum[f[k]-1];
}
define sum[m] and cost[n] @cheetah1
It works.

It is considered, go through the constraints.

1 Like