algorithm/c++

백준/1049/기타줄

아르르르를를르 2020. 2. 3. 00:36

문제 : https://www.acmicpc.net/problem/1049

 

#include <stdio.h>

int min(int a, int b){
    if(a <= b) return a;
    if(b <= a) return b;
}

int main(void){
    int N, M, result;
    scanf("%d %d", &N, &M);

    int das = N / 6;
    int mod = N % 6;

    int set = 10000;
    int each = 10000;
    for(int i=0;i<M;i++){
        int tmp1, tmp2;
        scanf("%d %d", &tmp1, &tmp2);
        if(tmp1 < set) set = tmp1;
        if(tmp2 < each) each = tmp2;
    }

    if(N<6) result = min(set, each*N);
    else{
        int all_set = set * das + set;
        int all_each = N * each;
        int fit = mod * each + set * das;
        result = min(fit, min(all_set, all_each));
    }
    printf("%d", result);
}

 

나중에 python으로 다시 품

def main(need, package_min, each_min):
    pack_num, each_num = need // 6, need % 6
    return min(pack_num*package_min, pack_num*6*each_min) + min(package_min, each_num*each_min)

if __name__ == '__main__':
    nm = input().split()
    nm = [int(i) for i in nm]
    need = nm[0]
    package_min = 10000
    each_min = 10000
    for _ in range(nm[1]):
        temp = input().split()
        temp = [int(i) for i in temp]
        if temp[0] < package_min:
            package_min = temp[0]
        if temp[1] < each_min:
            each_min = temp[1]
    ans = main(need, package_min, each_min)
    print(ans)

'algorithm > c++' 카테고리의 다른 글

백준/2753/윤년  (0) 2020.10.20
백준/4344/평균은 넘겠지  (0) 2020.10.18
c++ 입출력 최적화 방법  (0) 2020.10.18
백준/14891/톱니바퀴  (0) 2019.04.22
백준/4659/비밀번호 발음하기  (0) 2019.04.21