From 3496b0ed08c51e37e135e686b1632fd86f930c2c Mon Sep 17 00:00:00 2001 From: Raghuram Subramani Date: Mon, 30 Sep 2024 16:08:27 +0530 Subject: (init): Initialize repository. --- problems/budgettraveler.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 problems/budgettraveler.py (limited to 'problems/budgettraveler.py') diff --git a/problems/budgettraveler.py b/problems/budgettraveler.py new file mode 100644 index 0000000..40da77e --- /dev/null +++ b/problems/budgettraveler.py @@ -0,0 +1,18 @@ +def min_countries_to_visit(n, countries): + total_attractions = sum(y for _, y in countries) + countries.sort(key=lambda x: x[1], reverse=True) + attractions_count = 0 + countries_visited = 0 + half_attractions = total_attractions / 2 + + for _, attractions in countries: + attractions_count += attractions + countries_visited += 1 + if attractions_count >= half_attractions: + break + + return countries_visited + +n = int(input()) +countries = [tuple(map(int, input().split())) for _ in range(n)] +print(min_countries_to_visit(n, countries)) -- cgit v1.2.3