Skip to content

Commit aba7fa9

Browse files
author
Ayush Singh
committed
Add solution for day-06
1 parent dd9819c commit aba7fa9

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Approach
2+
- Sort the wealth array
3+
- Target the middle index to ensure more than half are unhappy
4+
- Solve inequality directly instead of using binary search
5+
6+
## Complexity
7+
- Time: O(n log n)
8+
- Space: O(n)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## C. Robin Hood in Town
2+
3+
Link: https://codeforces.com/contest/2014/problem/C
4+
5+
Determine the minimum extra gold required so that
6+
strictly more than half of the population becomes unhappy.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
input = sys.stdin.readline
3+
4+
t = int(input())
5+
6+
for _ in range(t):
7+
n = int(input())
8+
a = list(map(int, input().split()))
9+
10+
if n <= 2:
11+
print(-1)
12+
continue
13+
14+
a.sort()
15+
total = sum(a)
16+
17+
k = n // 2
18+
x = 2 * n * a[k] - total + 1
19+
20+
print(max(0, x))

0 commit comments

Comments
 (0)