diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2024-09-30 16:08:27 +0530 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2024-09-30 16:08:27 +0530 |
commit | 3496b0ed08c51e37e135e686b1632fd86f930c2c (patch) | |
tree | 1da44792489607070f3b4ca14d82af05b73e362b /problems/budgettraveler.py |
(init): Initialize repository.
Diffstat (limited to 'problems/budgettraveler.py')
-rw-r--r-- | problems/budgettraveler.py | 18 |
1 files changed, 18 insertions, 0 deletions
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)) |