0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

B - Iron Bar Cutting AtCoder

Posted at

問題

回答

n = int(input())
a = list(map(int, input().split()))
yen = 0
a_sum = sum(a) #累積和
ans = 99999999999999999 #累積和
for i in range(n):
    yen += a[i] # 1回目はa[0]を足し、2回目はa[0]とa[1]をたす、、と足していく。累積和。
    a_sum -= a[i] #1回目はa[0]をひく、2回目はa[0]とa[1]を足したものをひく、、と引いていく。累積和。
    ans = min(ans, abs(yen - a_sum)) #絶対値との差

print(ans)

ポイント

累計和の問題。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?