ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ 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
- ํ๋ก์ด๋์์ฌ
- ์๋ฐ
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- python3
- dfs
- BFS
- ์คํ
- ๋ธ๋ฃจํธํฌ์ค
- MongoDB
- dp
- ์ด๋ถํ์
- ํด์๋งต
- ๋ชฝ๊ณ ๋๋น
- ํ
- Macbook pro 2012 mid 13
- java
- ๋งฅ๋ถํ๋ก
- ๋ฐ๋
- ๋งฅ๋ถ
- ๋ฐฑ์ค
- go
- Golang
- ๋ถํ ์ ๋ณต
- ballet
- BOJ
- ์๊ฐ๊ต์ฒด
- Algorithm
- AWS
- baekjoon
- ์๊ณ ๋ฆฌ์ฆ
- Total
- Today
- Yesterday