Coding Test/softeer

[소프티어] 성격 평균- python (레벨 3)

조용장 2022. 5. 10. 19:45

https://softeer.ai/practice/info.do?eventIdx=1&psProblemId=389 

 

Softeer

연습문제를 담을 Set을 선택해주세요. 취소 확인

softeer.ai

풀이

문제를 보았을때 알수있는 힌트

단순하게 구간만 찾아서 평균내면 되는 문제이다.

이게 왜 레벨 3이지? 하는 생각이 들었다. 아마 반복문 2번 돌리면 안풀리기 때문인가?

파이썬으로 풀었다면 리스트 자체를 시작 끝을 찾아내기만 하면 되기에 정말 쉽게 풀 수 있다.

 

import sys

input = sys.stdin.readline

n,k = map(int,input().split())

n_list = list(map(int,input().split()))

for i in range(k):
    start,end =map(int,input().split())
    count=end-start+1
    print(f"{sum(n_list[start-1:end])/count:.2f}")