Help in Pintu and Fruits (CHPINTU)

Here is my code for the problem at CodeChef: Practical coding for everyone

#include <bits/stdc++.h>

using namespace std;

#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define rep(i,a,b) for(int i=a; i<b; i++)

#define pb push_back

#define inf 1e+18L

int main()



    int t;

    cin >> t;



        int n, m;

        cin >> n >> m;

        vector<int> f(n), p(n);

        rep(i,0,n) cin >> f[i];

        rep(i,0,n) cin >> p[i];

        vector<int> cost(m, 0);

        rep(i,0,n) cost[f[i]] += p[i];

        int minCost = INT_MAX;

        for(auto c : cost)


            if(c == 0)


            minCost = min(minCost, c);


        cout << minCost << "\n";


    return 0;


It works correctly for the sample test case but gives WA on submission. Where am I going wrong? Please help.

1 Like

@everule1 Please help.

1≤Fi≤M for each valid i
0≤Pi≤50 for each valid i

Hope this helps.

Some kind of overflow ?


1 2
0 1

I get 1 as the output.

It’s 0.

Why does the input contain only three lines? Shouldn’t it be four lines?

I forgot the input format, sorry.
Now I fixed it.

2 2
1 2
0 1

It gives 2147483647 as the output. That’s weird. Where is the fault?

minCost = INT_MAX.
You need to check if it is a possible answer, if minCost isn’t modified at all.

rep(i,0,n) cost[f[i]] += p[i];

What is the size of cost?, what is the maximum value of f[i].

1 Like

Thanks for the hint ! I finally got an AC.

1 Like