개발자/C or C++

[백준] 11399번

Mosser 2021. 10. 2.
728x90
반응형

이 문제는 그리디 알고리즘으로 풀었는데 정렬만 잘 사용하고 시간 계산만 잘한다면 쉽게 해결가능했다.

 

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

int main(){
    int numberOfperson;
    cin>>numberOfperson;
    if(numberOfperson<1 || numberOfperson>1000)
        return 0;

    int *time=new int[numberOfperson];
    int i,j;
    int sum=0;

    for(i=0;i<numberOfperson;i++){
        cin>>time[i];
        if(time[i]<1 || time[i]>1000)
            return 0;
    }

    sort(time,time+numberOfperson);

    for(i=1;i<numberOfperson;i++){
        for(j=0;j<=i;j++){
            sum+=time[j];
        }
        
    }
    sum+=time[0];

    cout<<sum<<endl;
    
}
반응형

'개발자 > C or C++' 카테고리의 다른 글

[백준] 10818번  (0) 2021.10.02
[백준] 2217번  (0) 2021.10.02
[백준] 11047번  (0) 2021.10.02
[백준] 2579번  (0) 2021.10.02
[백준] 1003번  (0) 2021.10.02

댓글