본문 바로가기

프로그래머스/LEVEL 1

[프로그래머스/LEVEL1] 부족한 금액 계산하기

문제

 

https://programmers.co.kr/learn/courses/30/lessons/82612

 

코딩테스트 연습 - 부족한 금액 계산하기

새로 생긴 놀이기구는 인기가 매우 많아 줄이 끊이질 않습니다. 이 놀이기구의 원래 이용료는 price원 인데, 놀이기구를 N 번 째 이용한다면 원래 이용료의 N배를 받기로 하였습니다. 즉, 처음 이

programmers.co.kr

 

코드

class Solution {
    public long solution(int price, int money, int count) {
		// 등차수열
		// 1 ~ n = (n*(1+n)) / 2
		long payment = price * ((long) count * (1 + count) / 2);
		long result = 0;

		result = (payment >= money) ? payment - money : 0;

		return result;
    }
}