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
2411 - secvp
(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 == <syntaxhighlight lang="python3" line="1"> import bisect def validate_input(n, k): if not (2 <= k <= n <= 100000): print("Invalid input. Please ensure 2 <= K <= N <= 100,000.") exit() fin = open("input.txt", "r") fout = open("output.txt", "w") N = 1000100 e = [0] * (N + 1) v = [] a = [0] * 100001 iteratii = [0] * 100001 sp = [0] * 100001 def ciur(): global v e[0] = e[1] = 1 for i in range(2, N + 1): if not e[i]: v.append(i) for j in range(i * 2, N + 1, i): e[j] = 1 def read_solve1(): global n, k, a, iteratii, sp n, k = map(int, fin.readline().split()) validate_input(n, k) s = 0 l=list(map(int, fin.readline().split())) for i in range(1, n + 1): x = l[i-1] it = bisect.bisect_left(v, x) it2 = bisect.bisect_right(v, x) d1 = it d2 = it2 if e[x]: if d1 > 0: s += min(abs(x - v[d1 - 1]), abs(x - v[d2])) iteratii[i] = min(abs(x - v[d1 - 1]), abs(x - v[d2])) if iteratii[i] == abs(x - v[d1 - 1]): iteratii[i] *= -1 else: s += abs(x - v[d2]) iteratii[i] = abs(x - v[d2]) a[i] = x + iteratii[i] if iteratii[i] < 0: iteratii[i] *= -1 sp[i] = sp[i - 1] + iteratii[i] fout.write(str(s)+"\n") def solve2(): global n, k, sp, mini, secv temp = 0 mini = float('inf') secv = 0 for i in range(k, n + 1): temp = sp[i] - sp[i - k] if temp < mini: mini = temp secv = 1 elif temp == mini: secv += 1 fout.write(str(mini)+" ") fout.write(str(secv)) if __name__ == "__main__": ciur() read_solve1() solve2() </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