diff --git a/003.py b/003.py new file mode 100644 index 0000000..1a84df1 --- /dev/null +++ b/003.py @@ -0,0 +1,22 @@ +#문제 003 구간합 구하기1 43 +import sys + + +input = sys.stdin.readline +a,b = map(int,input().split()) +list = list(map(int,input().split())) + +#합배열 만들기 +[5,4,3,2,1] + +sum_li = [0] +temp = 0 + +for i in list: + + temp += i + sum_li.append(temp) + +for i in range(b): + c,d = map(int,input().split()) + print(sum_li[d] - sum_li[c]) \ No newline at end of file diff --git a/006.py b/006.py new file mode 100644 index 0000000..6e72b12 --- /dev/null +++ b/006.py @@ -0,0 +1,17 @@ +n = int(input()) +count = 1 +start_index = 1 +end_index = 1 +sum = 1 +while end_index != n: + if sum == n: + count += 1 + end_index += 1 + sum += end_index + elif sum > n: + sum -= start_index + start_index += 1 + else: + end_index += 1 + sum += end_index +print(count) \ No newline at end of file diff --git a/007.py b/007.py new file mode 100644 index 0000000..8741eb5 --- /dev/null +++ b/007.py @@ -0,0 +1,19 @@ +import sys +input = sys.stdin.readline +N = int(input()); +M = int(input()); +A = list(map(int, input().split())) +A.sort() +count = int(0) +i = int(0) +j = int(N-1) +while i < j: # 투 포인터 이동 원칙 따라 포인터를 이동하며 처리 + if A[i] + A[j] < M: + i += 1 + elif A[i] + A[j] > M: + j -= 1 + else: + count += 1 + i += 1 + j -= 1 +print(count) \ No newline at end of file