https://programmers.co.kr/learn/courses/30/lessons/12927#
#include <string>
#include <vector>
#include <queue>
#include <math.h>
using namespace std;
bool cmp(int a, int b){
return a > b;
}
long long solution(int n, vector<int> works) {
long long answer = 0;
priority_queue<int, vector<int>, less<int>> q;
for(int i=0;i<works.size();i++)
q.push(works[i]);
for(int i=0;i<n;i++){
int in = q.top();
q.pop();
if(in == 0)
return 0;
q.push(in-1);
}
while(q.size() != 0){
answer += pow(q.top(), 2);
q.pop();
}
return answer;
}
#include <string>
#include <vector>
#include <queue>
using namespace std;
long long solution(int n, vector<int> works) {
long long answer = 0;
priority_queue<int>list(works.begin(), works.end());
int tmp;
while (n--)
{
tmp = list.top();
if (tmp > 0)
tmp--;
list.pop();
list.push(tmp);
}
while (!list.empty())
{
answer += (long long)list.top() * (long long)list.top();
list.pop();
}
return answer;
}