Gidhub BE Developer

BOJ - 카드 정렬하기

2018-02-18
goodGid

Problem

Problem URL : 카드 정렬하기

Screenshots of Problem Explain

[1] Answer Code (18. 02. 18)


#include<iostream>
#include<queue>
#include<functional>
#define ll long long
using namespace std;

int main(){
    int n;
    cin >> n;
    
    int tmp;
    priority_queue<int,vector<int>,greater<int> > q;
    
    for(int i=0; i<n; i++){
        scanf("%d",&tmp);
        q.push(tmp);
    }
    ll sum = 0;
    while (q.size() > 1) {
        int a,b;
        a = q.top();
        q.pop();
        b = q.top();
        q.pop();
        
        q.push(a+b);
        sum += a+b;
    }
    
    cout << sum << endl;
   
    return 0;
}



Code Review

[1] Answer Code (18. 02. 18)

  • 문제 잘못이해하고 풀어서 이상한 알고리즘 만들었음 …

Comments

Content