Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
3575 - Br
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Rezolvare ver. 1=== <syntaxhighlight lang="python" line="1" start="1"> def validate_input(n, t, c_values, rounds): if n < 1 or n > 15000: raise ValueError("Invalid number of friends") if t < 1 or t > 10000: raise ValueError("Invalid number of rounds") if len(c_values) != n: raise ValueError("Invalid number of beer costs") if any(ci < 1 or ci > 100 for ci in c_values): raise ValueError("Invalid beer cost") for k, x in rounds: if k < 1 or k > n: raise ValueError("Invalid friend index") if x < 1 or x > 3000000: raise ValueError("Invalid amount of money") def calculate_round_buying(n, c_values, k, x): beers_to_buy = [0] * n max_beers_bought = 0 total_cost = 0 for i in range(n): j = (k + i - 1) % n if total_cost + c_values[j] <= x: beers_to_buy[j] = 1 total_cost += c_values[j] max_beers_bought += 1 else: break if total_cost < x: for i in range(n): j = (k + i - 1) % n if beers_to_buy[j] == 0 and total_cost + c_values[j] <= x: beers_to_buy[j] = 1 total_cost += c_values[j] max_beers_bought += 1 if total_cost == x: break return max_beers_bought if __name__ == "__main__": try: with open("br.in") as f: n, t = map(int, f.readline().split()) c_values = list(map(int, f.readline().split())) rounds = [tuple(map(int, line.split())) for line in f] print("Datele introduse corespund restricțiilor impuse.") validate_input(n, t, c_values, rounds) with open("br.out", "w") as f: for k, x in rounds: f.write(str(calculate_round_buying(n, c_values, k, x)) + "\n") except Exception as e: print("Datele introduse nu corespund restricțiilor impuse.") </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width