CHPINTU - Editorial

Your code looks perfectly correct. Have you provided custom input? Except freq is initialised with -1, it should be initialised with 0.

“hidden traps”
Price = 0 :slight_smile:

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?

YUP

what IDE are you using

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 :sweat_smile:
Ohh Yes, and you’ve accessed mth index of t array which is out of bound
So, it’ll give runtime error

opchpintu

This o/p i am getting on my IDE but on codechef IDE it gives me runtime error:-segmentation fault

What’s wrong in my solution? Plz help
I have also considered that price can be 0
#include
#include
#include
#include
using namespace std;
#define ll long long int
int main()
{
ll t;
cin >> t;
while (t–)
{
ll n, m;
cin >> n >> m;
ll mf[m + 1], f[n + 1], p[n + 1];
for (ll i = 0; i <= m; i++)
mf[i] = 0;

        for (ll i = 1; i <= n; i++)
            cin >> f[i];

        for (ll i = 1; i <= n; i++)
            cin >> p[i];

        for (ll i = 1; i <= n; i++)
            mf[f[i]] += p[i];

        set<int> st;
        for (ll i = 1; i <= n; i++)
            st.insert(f[i]);

        ll ans = mf[1];
        for (ll i = 1; i <= m; i++)
        {
            if (st.find(i) != st.end())
                ans = min(ans, mf[i]);
        }

        cout << ans << "\n";
    }
}

I am also getting Run time error but my execution time is 0.002s.Any one know what’s happening?

What’s wrong?
#include

using namespace std;

struct basket

{

int value = 0;

int flag = 0;

};

int main()

{

int t;

cin >> t;

while (t--)

{

    int n, m;

    cin >> n >> m;

    int F[n], P[n];

    struct basket min[m];

    int minB = 1000000;

    for (int i = 0; i < m; ++i)

       cout <<  min[i].value ;

    for (int i = 0; i < n; ++i)

        cin >> F[i];

    for (int i = 0; i < n; ++i)

        cin >> P[i];

    for (int i = 0; i < n; ++i)

    {

        min[F[i]].value += P[i];

        min[F[i]].flag = 1;

    }

    for (int i = 0; i < m; i++)

    {

        if (minB > min[i].value && min[i].flag == 1)

            minB = min[i].value;

    }

    cout << minB << endl;

}

return 0;

}

Hi pro coders, please help me, I am gettng 0 score, despite getting correct outputs :slightly_frowning_face: CodeChef: Practical coding for everyone