The vicinity of phase transitions selectively amplifies weak stimuli, yielding optimal sensitivity to distinguish external input. Along with this enhanced sensitivity, enhanced levels of fluctuations at criticality reduce the specificity of the response. Given that the specificity of the response is largely compromised when the sensitivity is maximal, the overall benefit of criticality for signal processing remains questionable. Here, it is shown that this impasse can be solved by heterogeneous systems incorporating , in which critical and subcritical components coexist. The subnetwork of critical elements has optimal sensitivity, and the subnetwork of subcritical elements has enhanced specificity. Combining segregated features extracted from the different subgroups, the resulting collective response can maximize the trade-off between sensitivity and specificity measured by the dynamic-range-to-noise ratio. Although numerous benefits can be observed when the entire system is critical, our results highlight that optimal performance is obtained when only a small subset of the system is at criticality.