각종 노하우 분류

각종 노하우 [C를 활용한 문제해결 기법의 근간] 학습용!! adding cost

컨텐츠 정보

본문

[출처: Gamezone]
작성자: 작성자 없음

 


#define _CRE_SECURE_NO_WARNINGS

#pragma warning(disable:4996)

#include<cstdio>  

#include<queue>  

#include<functional>


#define MAXN 5005  

using namespace std;


priority_queue<long long, vector<long long>, greater<long long> >que;


int main() {


    int N;

    long long m;


    while (fscanf(input_file, "%d", &N) &&N) {

        if (N == 0) {

            break;

        }

        while (!que.empty()) que.pop();

        for (int i = 0; i<N; ++i) {

            fscanf(input_file,"%lld", &m);

            que.push(m);

        }

        long long sum = 0, ans = 0, a, b, t;

        while (!que.empty()) {

            a = que.top();

            que.pop();

            if (que.empty()) break;

            b = que.top();

            que.pop();

            sum = a + b;

            ans += sum;

            que.push(sum);

        }

        fprintf(output_file,"%lld\n", ans);

    }

    return 0;

}

관련자료

댓글 0
등록된 댓글이 없습니다.
각종 노하우 99 / 6 페이지
번호
제목
이름
MMOZONE (0명)

대도서관

🏆 포인트 랭킹 TOP 10
순위 닉네임 포인트
1 no_profile 코오롱쪽지보내기 자기소개 아이디로 검색 전체게시물 183,962
2 no_profile 보거스쪽지보내기 자기소개 아이디로 검색 전체게시물 164,191
3 no_profile 타키야겐지쪽지보내기 자기소개 아이디로 검색 전체게시물 160,729
4 no_profile 개굴개굴쪽지보내기 자기소개 아이디로 검색 전체게시물 137,078
5 no_profile 불멸의행복쪽지보내기 자기소개 아이디로 검색 전체게시물 134,599
6 no_profile Ragna쪽지보내기 자기소개 아이디로 검색 전체게시물 129,691
7 no_profile Omega쪽지보내기 자기소개 아이디로 검색 전체게시물 129,329
8 서번트쪽지보내기 자기소개 아이디로 검색 전체게시물 128,516
9 no_profile 베가쪽지보내기 자기소개 아이디로 검색 전체게시물 112,546
10 no_profile 검은고양이쪽지보내기 자기소개 아이디로 검색 전체게시물 105,974
알림 0