Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

PAIRING - Editorial

$
0
0

PROBLEM LINKS

Practice
Contest

DIFFICULTY

EASY

EXPLANATION

A greedy strategy works here. Consider the pairs in the reverse of the order they appear. When considering a given pair, we greedily take it if neither of the chefs were in a used pair earlier. To see why this is optimum, suppose an optimum solution had a higher total value than our greedy solution. Let i be the greatest index where our solution disagrees with the optimum. Based on our greedy selection strategy, it must be that we took the i'th pair whereas the optimum doesn't include the i'th pair. But then we can improve the cost of the optimum solution by deleting all pairs j with j < i and adding pair i. This is an improvement because of the exponentially increasing values of the pairs: 2^1 + 2^2 + ... + 2^{i-1} is strictly smaller than 2^i. This contradicts optimality of the considered solution.

SETTER'S SOLUTION

Can be found here.

TESTER'S SOLUTION

Can be found here.


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>