Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1주차 과제 #2

Open
wants to merge 1 commit into
base: 1주차
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions 003.py
Original file line number Diff line number Diff line change
@@ -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])
17 changes: 17 additions & 0 deletions 006.py
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 19 additions & 0 deletions 007.py
Original file line number Diff line number Diff line change
@@ -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)