# CHEFINSQ : Long challenge video editorial

**URL:** <https://discuss.codechef.com/t/chefinsq-long-challenge-video-editorial/38082>\
**Category:** editorial\
**Tags:** combinatorics, long-contest, video-editorials\
**Created:** [September 16, 2019, 9:32am UTC](https://discuss.codechef.com/t/chefinsq-long-challenge-video-editorial/38082 "2019-09-16T09:32:33Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![waqar\_ahmad224](https://discuss.codechef.com/user_avatar/discuss.codechef.com/waqar_ahmad224/32/27393_2.png) [@waqar\_ahmad224](https://discuss.codechef.com/u/waqar_ahmad224)\
**Post date:** [September 16, 2019, 9:32am UTC](https://discuss.codechef.com/t/chefinsq-long-challenge-video-editorial/38082/1 "2019-09-16T09:32:33Z")

</div>

Difficulty : Easy

[CHEFINSQ](https://youtu.be/oMyGhNX_dkk)

suggestions are always welcome for making this channel better.  
You guys are requested to support this channel by subscribing.  
Thank you.  
Happy Coding.

---

<div class="post-metadata">

**Author:** ![rohitkk074](https://discuss.codechef.com/user_avatar/discuss.codechef.com/rohitkk074/32/26688_2.png) [@rohitkk074](https://discuss.codechef.com/u/rohitkk074)\
**Post date:** [September 16, 2019, 2:23pm UTC](https://discuss.codechef.com/t/chefinsq-long-challenge-video-editorial/38082/2 "2019-09-16T14:23:38Z")

</div>

Hey , I solved the question using a different approach. Though it’s inefficient but it works for the given set of constraints and quite straight forward.

[solution](https://www.codechef.com/viewsolution/26354946)

---

<div class="post-metadata">

**Author:** ![waqar\_ahmad224](https://discuss.codechef.com/user_avatar/discuss.codechef.com/waqar_ahmad224/32/27393_2.png) [@waqar\_ahmad224](https://discuss.codechef.com/u/waqar_ahmad224)\
**Post date:** [September 16, 2019, 5:35pm UTC](https://discuss.codechef.com/t/chefinsq-long-challenge-video-editorial/38082/3 "2019-09-16T17:35:27Z")

</div>

well it’s so easy problem that almost all solutions seem straight forward.

---

<div class="post-metadata">

**Author:** ![rohitkk074](https://discuss.codechef.com/user_avatar/discuss.codechef.com/rohitkk074/32/26688_2.png) [@rohitkk074](https://discuss.codechef.com/u/rohitkk074)\
**Post date:** [September 16, 2019, 6:06pm UTC](https://discuss.codechef.com/t/chefinsq-long-challenge-video-editorial/38082/4 "2019-09-16T18:06:21Z")

</div>

Yeah I agree with you.

---

<div class="post-metadata">

**Author:** ![waqar\_ahmad224](https://discuss.codechef.com/user_avatar/discuss.codechef.com/waqar_ahmad224/32/27393_2.png) [@waqar\_ahmad224](https://discuss.codechef.com/u/waqar_ahmad224)\
**Post date:** [September 17, 2019, 4:20am UTC](https://discuss.codechef.com/t/chefinsq-long-challenge-video-editorial/38082/5 "2019-09-17T04:20:58Z")

</div>

well what was your approach?

---

<div class="post-metadata">

**Author:** ![rohitkk074](https://discuss.codechef.com/user_avatar/discuss.codechef.com/rohitkk074/32/26688_2.png) [@rohitkk074](https://discuss.codechef.com/u/rohitkk074)\
**Post date:** [September 17, 2019, 7:31am UTC](https://discuss.codechef.com/t/chefinsq-long-challenge-video-editorial/38082/6 "2019-09-17T07:31:09Z")

</div>

I’m not really good at explaining, but I’ll give it a try.  
So here’s what I thought :  
Say that I’m at **i** th index, what are the things that I need to know that will help me uniquely identify the state.

Turns out there are three things :  
1 -\> the current index I’m at  
2 -\> the current sum that I’ve achieved, and  
3 -\> the number of elements in the set.  
These three things will help me uniquely identify any position/state.

For any index there are two possibilities , either I include that index in the current set or exclude it.  
Now the rest part is just backtracking and memoization.  
**dp[idx][sum][count] = solve(idx-1,sum,count,mins,a) + solve(idx-1,sum+a[idx],count+1,mins,a);**

Hope that I was clear enough 🙂

---

<div class="post-metadata">

**Author:** ![waqar\_ahmad224](https://discuss.codechef.com/user_avatar/discuss.codechef.com/waqar_ahmad224/32/27393_2.png) [@waqar\_ahmad224](https://discuss.codechef.com/u/waqar_ahmad224)\
**Post date:** [September 17, 2019, 9:50am UTC](https://discuss.codechef.com/t/chefinsq-long-challenge-video-editorial/38082/7 "2019-09-17T09:50:03Z")

</div>

That is a good approach too 👍

---

<div class="post-metadata">

**Author:** ![dat\_ass](https://discuss.codechef.com/user_avatar/discuss.codechef.com/dat_ass/32/3653_2.png) [@dat\_ass](https://discuss.codechef.com/u/dat_ass)\
**Post date:** [September 18, 2019, 3:02am UTC](https://discuss.codechef.com/t/chefinsq-long-challenge-video-editorial/38082/8 "2019-09-18T03:02:19Z")

</div>

looks like you are good in dp.

---

<div class="post-metadata">

**Author:** ![rohitkk074](https://discuss.codechef.com/user_avatar/discuss.codechef.com/rohitkk074/32/26688_2.png) [@rohitkk074](https://discuss.codechef.com/u/rohitkk074)\
**Post date:** [September 18, 2019, 4:36am UTC](https://discuss.codechef.com/t/chefinsq-long-challenge-video-editorial/38082/9 "2019-09-18T04:36:39Z")

</div>

Recently started but errichto videos helped me in getting the concepts.

---

<div class="post-metadata">

**Author:** ![meetpandya4715](https://discuss.codechef.com/user_avatar/discuss.codechef.com/meetpandya4715/32/3653_2.png) [@meetpandya4715](https://discuss.codechef.com/u/meetpandya4715)\
**Post date:** [September 18, 2019, 8:11am UTC](https://discuss.codechef.com/t/chefinsq-long-challenge-video-editorial/38082/10 "2019-09-18T08:11:42Z")

</div>

can anyone tell me why this code isn’t working?  
[solution](https://www.codechef.com/viewsolution/26643169)

---

<div class="post-metadata">

**Author:** ![ssjgz](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ssjgz/32/346011_2.png) [@ssjgz](https://discuss.codechef.com/u/ssjgz)\
**Post date:** [September 18, 2019, 8:16am UTC](https://discuss.codechef.com/t/chefinsq-long-challenge-video-editorial/38082/11 "2019-09-18T08:16:30Z")

</div>

As with other solutions, it fails on the testcase [here](https://discuss.codechef.com/t/chefinsq-editorial/37727/11).

---

<div class="post-metadata">

**Author:** ![meetpandya4715](https://discuss.codechef.com/user_avatar/discuss.codechef.com/meetpandya4715/32/3653_2.png) [@meetpandya4715](https://discuss.codechef.com/u/meetpandya4715)\
**Post date:** [September 18, 2019, 10:23am UTC](https://discuss.codechef.com/t/chefinsq-long-challenge-video-editorial/38082/12 "2019-09-18T10:23:30Z")

</div>

added constraint, but didn’t help… same issue  
[solution](https://www.codechef.com/viewsolution/26644034)
