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
1728 - K Sum Dif
(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!
= Restricții și precizări = * <code>1 ≤ n ≤ 10000</code> * cele <code>n</code> elemente ale vectorului vor fi mai mici decât <code>1000</code> * <code>k≤50</code> == Exemplul 1 == Input: 6 3 5 2 4 9 3 1 Output: 32 Explicație: Prelucrarea primului element al noului vector se face astfel: <code>(5+2)-(5-2)=4</code> , Elementele primului vector construit vor fi: <code>4 4 8 6 2</code> . Elementele celui de-al 2-lea vector construit vor fi: <code>8 8 12 4</code> , iar suma lor va fi <code>32</code> . == Exemplul 2 == Input: 99999999 1 5 2 4 9 3 1 Output: Conditions not met. == Rezolvare == <syntaxhighlight lang="python3" line="1"> def verify_conditions(n, k, v): if 1 <= n <= 10000 and k <= 50 and all(0 <= x < 1000 for x in v): return True return False n, k = map(int, input().split()) v = list(map(int, input().split())) if verify_conditions(n, k, v): while k > 1: for i in range(n - 1): v[i] += (v[i + 1] - abs(v[i] - v[i + 1])) n -= 1 k -= 1 s = sum(v[:n]) print(s) else: print("Conditions not met.") </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