affiche juste le code, pas d'explications !
- User
System: affiche juste le code, pas d'explications ! User: Tu es un développeur python3 expérimenté, et tu dois concevoir un programme en python (avec des commentaires en français, sans utiliser de librairies externes, sans
if __name__=="__main__":, avec type hints, et en privilégiant les algorythmes a complexité constante (O(1)) et/ou complexité linéaire (O(n))). Le programme va recevoir les données en entrée sur la stdin, et doit répondre sur la stdout. Fabrique moi un programme python qui résout le problème (énoncé en markdown) suivant :Trash cans - The most beautiful trash can
The moment you've been waiting for is finally here! You've just moved into your new apartment, and now you can finally make the most important and exciting decision of your life: buying a garbage can.
But it's not so easy: you need a big enough garbage can, and the prettiest one possible, of course!
You have at your disposal the volume and the beauty of the different garbage cans available, and you have to find the most beautiful one to have a volume of at least 20 liters. How beautiful will the chosen garbage can be?
Data
Input
Line 1 : an integer
Nbetween 1 and 100, representing the number of available garbage cans.N following lines : one garbage can per line. Each garbage can is described by two integers, separated by a space. The first one represents the volume in liters of the garbage can, the second one its beauty.
Output
The maximum beauty of a sufficiently large garbage can (at least 20 liters). We guarantee that there will always be at least one garbage can of at least 20 liters.
Example
For the input :
4 30 25 20 40 10 50 20 30The expected output is:
40In fact, the most beautiful of the garbage cans among those that have a volume of at least 20 liters is the one that has a beauty of 40. Assistant:
- Assistant
def trouver_beaute_maximale(lignes: list[str]) -> int: # Récupérer le nombre de poubelles N = int(lignes[0]) # Variable pour conserver la beauté maximale trouvée beaute_maximale = 0 # Parcourir les poubelles disponibles pour trouver la beauté maximale avec un volume suffisant for i in range(1, N + 1): volume, beaute = map(int, lignes[i].split()) # Vérifier si le volume est suffisant if volume >= 20: # Mettre à jour la beauté maximale si nécessaire if beaute > beaute_maximale: beaute_maximale = beaute return beaute_maximale import sys lignes = [ligne.strip() for ligne in sys.stdin] print(trouver_beaute_maximale(lignes))