IOC - Editorial

chef
corp2018
easy
editorial
greedy
sorting

#1

PROBLEM LINK:

Practice
Contest

Author: Jarin Gupta
Tester: Aanya Jindal
Editorialist: Gaurav Aggarwal

DIFFICULTY:

EASY

PREREQUISITES

Sorting

PROBLEM:

N cakes are given. Cut k of them parallel to any edge to maximise the sum of perimeters of rectangles.

EXPLANATION:

We have a total of N cakes, each ith cake having a length li and breadth bi (1 <= i <= n).

For any ith cake, to divide it into 2 rectangles and maximise the perimeter, we have to cut it parallel to Xi = max(li,bi). The extra perimeter so formed will be Yi = 2 * Xi.

horizontal cut

vertical cut

So we store the extra perimeters each cake gives, sort them and pick the k maximum cakes from them to cut.

AUTHOR’S AND TESTER’S SOLUTIONS:

Author’s solution can be found here.
Tester’s solution can be found here.