Post

[Programmers] #120830 - 양꼬치 [Java][C++][Python]

[Programmers] #120830 - 양꼬치 [Java][C++][Python]

문제 링크


1. 아이디어

양꼬치 n인분은 1인분당 12,000원, 음료수는 1개당 2,000원이고 10인분마다 음료수 1개가 무료로 제공된다. 따라서 총 금액은 $n \times 12{,}000 + (k - \lfloor n / 10 \rfloor) \times 2{,}000$으로, 마신 음료수 k개 중 서비스로 받은 $\lfloor n / 10 \rfloor$개를 제외한 나머지만 값을 매기면 된다.


2. 복잡도

접근시간공간
풀이$O(1)$$O(1)$

3. 코드

풀이 [Java][C++][Python]

1
2
3
4
5
class Solution {
    public int solution(int n, int k) {
        return n * 12000 + (k - n / 10) * 2000;
    }
}
1
2
3
4
5
6
#include <bits/stdc++.h>
using namespace std;

int solution(int n, int k) {
    return n * 12000 + (k - n / 10) * 2000;
}
1
2
def solution(n, k):
    return n * 12000 + (k - n // 10) * 2000

This post is licensed under CC BY 4.0 by the author.