알고리즘

[알고리즘] 백준 1350 - 진짜 공간 (C++)

blueberrysoda 2024. 11. 29. 23:48

[문제 링크] : https://www.acmicpc.net/problem/1350

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

int N, M;
long long inp, Ans = 0;
vector<int> V;

int main(){
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> inp;
        V.push_back(inp);
    }

    cin >> M;
    for(int i=0; i<N; i++){
        if(V[i] > M){
            if(V[i] % M == 0){
                Ans += V[i] / M;
            }
            else{
                Ans += V[i] / M + 1;
            }
        }
        else if(V[i] != 0){
            Ans += 1;
        }
    }
    cout << Ans * M << "\n";
    return 0;
}