# STUDCOMP - Editorial

**URL:** <https://discuss.codechef.com/t/studcomp-editorial/86326>\
**Category:** editorial\
**Created:** [March 1, 2021, 5:55pm UTC](https://discuss.codechef.com/t/studcomp-editorial/86326 "2021-03-01T17:55:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sigma\_g](https://discuss.codechef.com/user_avatar/discuss.codechef.com/sigma_g/32/24644_2.png) [@sigma\_g](https://discuss.codechef.com/u/sigma_g)\
**Post date:** [March 1, 2021, 5:55pm UTC](https://discuss.codechef.com/t/studcomp-editorial/86326/1 "2021-03-01T17:55:30Z")

</div>

# STUDCOMP

[Contest](https://www.codechef.com/DGTC2021/problems/STUDCOMP)  
[Practice](https://www.codechef.com/problems/STUDCOMP)

_ **Author:** _ [`sigma_g`](https://www.codechef.com/users/sigma_g)  
_ **Tester:** _ [multiple, see announcement](https://discuss.codechef.com/t/invitation-to-decode-2021-from-felicity-threads-iiit-h/86219)  
_ **Editorialist:** _ [`sigma_g`](https://www.codechef.com/users/sigma_g)

# DIFFICULTY:

EASY

# PREREQUISITES:

Sets

# PROBLEM

Determine - for each j - whether a set of indices exists such that all elements in it have m\_i lower than that of m\_j, but their sum of a\_i is larger than that of a\_j.

# Buggy code plain text

[Pastebin](https://pastebin.com/W6mvJBBb)

# QUICK EXPLANATION

> **Spoiler**
>
> The code uses `set` whereas it should be using `multiset`, for the appreciation values.

# EXPLANATION

> **Step 1**
>
> Note that there are other possible decoy bugs in this problem. For example, you might think the complexity of the inner loop (`for (auto x : apps)` ) is linear in `n` , and consider this problem a candidate for TLE. However, the inner `if` condition will break within 20 iterations (as 20 \>= `a[i] >= 1` , so there is no TLE in this problem.

> **Step 2**
>
> Note that there might be duplicates in the appreciation values `a` . Is there a bug in the code related to this?

> **Step 3**
>
> The `set<int> apps` has to be a `multiset<int>` . Any careful testcase with repeating values of `a` will exploit this, for example:
> 
> ```auto
> 3
> 2 3 4
> 4 4 7
> 
> ```
> 
> But not all repeating values will work, for example, something simpler like:
> 
> ```auto
> 2
> 2 3
> 4 4
> 
> ```
> 
> doesn’t hack the buggy solution.

# Setter’s solution

> **Text**
>
> ```auto
> 5
> 1 1 1 1 10
> 5 5 5 5 20
> 
> ```
