File tree Expand file tree Collapse file tree
Problems/Binary-Search/Day-06/sol/ayush2005k Expand file tree Collapse file tree Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ """
2+ Problem: C. Robin Hood in Town
3+ Link: https://codeforces.com/contest/2014/problem/C
4+
5+ Short Problem Statement:
6+ There are n people with given wealth.
7+ The richest person finds extra gold.
8+ A person is unhappy if their wealth is less than half of the average.
9+ Find the minimum gold required so that more than half the population becomes unhappy.
10+
11+ Approach:
12+ - If n <= 2, it is impossible.
13+ - Sort the wealth array.
14+ - To make strictly more than n/2 people unhappy, it is sufficient to
15+ make the person at index n//2 unhappy (0-based).
16+ - Derive the inequality directly and compute the minimum required gold.
17+
18+ Time Complexity:
19+ O(n log n)
20+
21+ Space Complexity:
22+ O(n)
23+
24+ Example:
25+ Input:
26+ 4
27+ 1 2 3 4
28+
29+ Output:
30+ 15
31+
32+ Submission Link:
33+ https://codeforces.com/contest/2014/submission/356103335
34+ """
35+
136import sys
237input = sys .stdin .readline
338
You can’t perform that action at this time.
0 commit comments