[BOJ / C++] 1049 기타줄

Seulguo·2022년 7월 21일
0

Algorithm

목록 보기
113/185
post-thumbnail
post-custom-banner

🐣 문제

링크 : https://www.acmicpc.net/problem/1049


🐥 코드

/*
문제 : 기타줄
링크 : https://www.acmicpc.net/problem/1049
*/

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;

    vector<int> v;
    vector<int> many_set;
    vector<int> one_set;
    for(int i = 0; i < M; i++){
        int many, one;
        int q, r;
        cin >> many >> one;

        many_set.push_back(many);
        one_set.push_back(one);
    }

    sort(many_set.begin(), many_set.end());
    sort(one_set.begin(), one_set.end());

    if(N < 6){
        if(many_set[0] < one_set[0] * N) cout << many_set[0];
        else cout << one_set[0] * N;
    }

    else{
        int q = N / 6;
        int r = N % 6;

        int a = many_set[0] * q + r * one_set[0];
        int b = 0;
        if(r == 0) b = many_set[0] * q;
        else b = many_set[0] * (q + 1);
        int c = one_set[0] * N;


        if(a <= b && a <= c) cout << a;
        else if(b <= a && b <= c) cout << b;
        else cout << c;
    }
     return 0;
}
post-custom-banner

0개의 댓글