ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
1392๋ฒ: ๋ ธ๋ ์ ๋ณด
์ฒซ ์ค์๋ ์ ๋ณด ์ N(1 ≤ N ≤ 100)๊ณผ ์ง๋ฌธ์ ๊ฐ์ Q(1 ≤ Q ≤ 1,000)๊ฐ ์ฃผ์ด์ง๋ค. ๋ค์ N๊ฐ์ ์ค์๋ 1๋ฒ ์ ๋ณด๋ถํฐ N๋ฒ ์ ๋ณด๊น์ง ๊ฐ ์ ๋ณด๊ฐ ์ฐจ์งํ๋ ์๊ฐ(์ด)์ด ํ ์ค์ ํ๋์ฉ ์ฃผ์ด์ง๋ค. ๊ฐ ์ ๋ณด๊ฐ
www.acmicpc.net
โ๐ป ํ์ด
๐จ Go
// https://www.acmicpc.net/problem/1392
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
writer := bufio.NewWriter(os.Stdout)
defer writer.Flush()
var n, q int
fmt.Fscanln(reader, &n, &q)
var scores []int
for i := 0; i < n; i++ {
var seconds int
fmt.Fscanln(reader, &seconds)
if i == 0 {
scores = append(scores, seconds)
} else {
scores = append(scores, scores[i-1]+seconds)
}
}
var questions []int
for i := 0; i < q; i++ {
var seconds int
fmt.Fscanln(reader, &seconds)
questions = append(questions, seconds)
}
for i := 0; i < q; i++ {
var question = questions[i]
for j := 0; j < n; j++ {
if scores[j] > question {
fmt.Fprintln(writer, j+1)
break
}
}
}
}
๐จ Python3
# https://www.acmicpc.net/problem/1392
import sys
if __name__ == "__main__":
n, q = list(map(int, sys.stdin.readline().split()))
scores = []
for i in range(n):
seconds = int(sys.stdin.readline())
if i == 0:
scores.append(seconds)
else:
scores.append(scores[i-1]+seconds)
questions = []
for i in range(q):
seconds = int(sys.stdin.readline())
questions.append(seconds)
for i in range(q):
question = questions[i]
for j in range(n):
if scores[j] > question:
print(j+1)
break
728x90
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 10708๋ฒ / ํฌ๋ฆฌ์ค๋ง์ค ํํฐ [Go][Python3] (0) | 2020.12.25 |
---|---|
BOJ / 4573๋ฒ / Pizza Pricing [Go][Python3] (0) | 2020.12.22 |
BOJ / 2947๋ฒ / ๋๋ฌด ์กฐ๊ฐ [Go][Python3] (0) | 2020.12.18 |
BOJ / 2468๋ฒ / ์์ ์์ญ [Go][Python3] (0) | 2020.12.16 |
BOJ / 2667๋ฒ / ๋จ์ง๋ฒํธ๋ถ์ด๊ธฐ [Go][Python3] (0) | 2020.12.15 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ballet
- ์ด๋ถํ์
- ํด์๋งต
- ์๊ณ ๋ฆฌ์ฆ
- ์คํ
- ํ
- ๋ฐฑ์ค
- java
- baekjoon
- ์๊ฐ๊ต์ฒด
- ๋ชฝ๊ณ ๋๋น
- ๋ธ๋ฃจํธํฌ์ค
- ๋งฅ๋ถํ๋ก
- go
- ํ๋ก์ด๋์์ฌ
- dp
- Golang
- MongoDB
- BFS
- dfs
- AWS
- ์๋ฐ
- python3
- Algorithm
- BOJ
- Macbook pro 2012 mid 13
- ๋ฐ๋
- ๋งฅ๋ถ
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- ๋ถํ ์ ๋ณต
- Total
- Today
- Yesterday