--- tags: csc --- {%hackmd theme-dark %} Computer Science Club (3) === Note --- [[PYTHON] LIST 篇](https://happylearningcoding.blogspot.com/2020/07/python-list.html) List Usage --- ### dandanjudge [a004: 經濟大恐荒](http://dandanjudge.fdhs.tyc.edu.tw/ShowProblem?problemid=a004) 題意 : `ans = sum(a[i] * (i + 1))` ```python= n = int(input()) lst = [int(x) for x in input().split()] res = 0 for i in range(n): res += lst[i] * (i + 1) print(res) ``` [a164. 0927進階班作業-區間和](http://dandanjudge.fdhs.tyc.edu.tw/ShowProblem?problemid=a164) `data` | 0 | 1 | 2 | 3 | 4 | 5 | | - | - | - | - | - | - | `accumulate` | 0 | 1 | 3 | 6 | 10 | 15 | | - | - | - | - | - | - | 區間和 $=$ `accumulate[r]` $-$ `accumuate[l - 1]` `code` ```python= lst = [0] + [int(x) for x in input().split()] # data for i in range(1, len(lst)): lst[i] += lst[i - 1] # accumulate n = int(input()) for _ in range(n): l, r = [int(x) for x in input().split()] if l > r: l, r = r, l print(lst[r] - lst[l - 1]) ```