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
2150 - Credite
(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!
= Exemplul 1: = <code>crediteIN.txt</code> 4 10 3 7 5 8 1 2 1 <code>crediteOUT.txt</code> 25 === Explicație === Maria alege să rezolve problema 3, renunțând la problema 4 pentru ca are mai puține credite și același timp limită ca problema 3. După aceea va rezolva problemele 1 și 2, adunând în total 25 de credite. == Exemplul 2: == <code>crediteIN.txt</code> 10001 10 3 7 5 8 1 2 1 <code>crediteOUT.txt</code> Datele nu corespund restrictiilor impuse == Rezolvare == <syntaxhighlight lang="python3" line="1"> import heapq def verifica_restrictii(n, v): if not (2 <= n <= 10000): return False for nrC, timpul in v: if not (2 <= nrC <= 1000) or not (1 <= timpul <= 10000): return False return True def main(): with open("crediteIN.txt", "r") as fin, open("crediteOUT.txt", "w") as fout: n = int(fin.readline()) ans = 0 v = [] timp = [False] * 10001 tmax = 0 for _ in range(n): line = fin.readline().strip() if not line: continue # Ignoră liniile goale vals = line.split() if len(vals) < 2: fout.write("Datele din fisier nu sunt formatate corect") return nrC, timpul = map(int, vals) v.append((nrC, timpul)) if timpul > tmax: tmax = timpul timp[timpul] = True if not verifica_restrictii(n, v): fout.write("Datele nu corespund restrictiilor impuse") return q = [] for i in range(tmax, 0, -1): if timp[i]: for nrC, timpul in v: if timpul == i: heapq.heappush(q, (-nrC, timpul)) if q: nrC, timpul = heapq.heappop(q) ans += -nrC fout.write(str(ans)) if __name__ == "__main__": main() </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