Skip to content

Commit c2c8b8f

Browse files
author
Ayush Singh
committed
Add Day-06 solution
1 parent aba7fa9 commit c2c8b8f

3 files changed

Lines changed: 35 additions & 14 deletions

File tree

Problems/Binary-Search/Day-06/sol/ayush2005k/notes.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

Problems/Binary-Search/Day-06/sol/ayush2005k/problem.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

Problems/Binary-Search/Day-06/sol/ayush2005k/solution.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,38 @@
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+
136
import sys
237
input = sys.stdin.readline
338

0 commit comments

Comments
 (0)