what is wrong in this------------
tc = int(input())
while tc:
n, m = list(map(int, input().split()))
fruits = list(map(int, input().split()))
prices = list(map(int, input().split()))
presence_array = [0]*m
for i in range(1, m+1):
if i in fruits:
presence_array[i-1] = True
else:
presence_array[i-1] = False
c = presence_array.count(True)
new_array = [0]*c
for i in range(len(fruits)):
new_array[fruits[i]-1] += prices[i]
print(min(new_array))
tc -= 1
in your nested loop make the following changes to your inner loop:
for (int j=0;j<n;j++)
{
if(f[i]==f[j])
{
p[i]=p[i]+p[j];// i also recommend to use a new array instead of using p[i]
}
}
also when finding the minimum element in the price array don’t skip over zero as a type of fruit may also have zero price (see the constraints carefully)
Please, can you help me, I am getting zero- socre , but i am getting the correct output.
PLEASE HELP .
t=int(input())
n_barrrier,n_type=map(int,input().split())
lis1=list(map(int,input().split()))
lis2=list(map(int,input().split()))
lis3=[]
for i in range(t):
for i in range(1,n_type+1):
sum=0
c=False
for j in range(n_barrrier):
if i==lis1[j]:
sum+=lis2[j]
lis1[j]=0
c=True
if c==True:
lis3.append(sum)
print(min(lis3))
why do i get SIGSEV here in this code and how to deal with this I am new to this platform.
int main() {
int t;
cin>>t;
while(t!=0){
int n,m;
cin>>n>>m;
int f[n],p[n];
for(int i=0;i<n;i++)
cin>>f[i];
for(int i=0;i<n;i++)
cin>>p[i];
int freq[m+1];
bool avail[m+1];
memset(avail,false,sizeof(avail));
memset(freq,-1,sizeof(freq));
for(int i=0;i<n;i++){
freq[f[i]]+=p[i];
avail[f[i]]=true;
}
int min = INT_MAX;
for(int i=0;i<=m;i++){
if(freq[i]<min && avail[i]==true){
min=freq[i];
}
}
cout<<min<<"\n";
t--;
}
return 0;
}
Your code looks perfectly correct. Have you provided custom input? Except freq is initialised with -1, it should be initialised with 0.
Yup but nothing worked for me
Initialized freq with 0
Runtime error :- SIGTSTP
https://www.codechef.com/viewsolution/30571717
I just added the header files and the namespace, and changed freq to 0, Which I am presuming you’ve done in your code.
Why just I don’t know sometimes it gives sigsegv or sigtstp even i have done the changes suggested by you @everule1
Are you sure you’re providing custom input?
Online IDE by Codechef :- C++14(Gcc 6.3)
further I also compiled it on my IDE(DEV C++) it provided me the correct output .
but the IDE provided by codechef gives the run time error
but it has the condition for price = 0…
It must be cause you dont have any other problems
Or initializing maybe a issue, otherwise your code must pass.
#include<bits/stdc++.h>
using namespace std;
int main(){
// m types of fruit
// n number
// fi -> fruit types
// pi -> cost
int t;
cin>>t;
while(t--){
int m , n;
cin>>n>>m;
int *fi=new int[n];
int *pi=new int[n];
int *ti =new int[m];
for(int i=0;i<n;i++){
cin>>fi[i];
}
for(int i=0;i<n;i++){
cin>>pi[i];
}
for(int j=1 ;j<=m;j++){
ti[j]=0;
}
int min=0;
for(int i=0 ;i<n;i++){
ti[fi[i]]+=pi[i];
}
min = ti[1];
for(int i=2;i<=m;i++){
// min=ti[i];
if(min >ti[i] && ti[i]!=0){
min=ti[i];
}
}
cout<<min<<endl;
delete fi;
delete pi;
delete ti;
}
return 0;
}
what`s wrong in this code
Why t[i] != 0, Price of fruit can be zero.
For these logic you need a flag array to indicate which type of fruits have occurred.
Sorry, bro, I don’t use pointers for arrays
You’ve used delete pointer and pointers for creating an array which is kind of unsettling for me 
Ohh Yes, and you’ve accessed mth index of t array which is out of bound
So, it’ll give runtime error