문제출처 : https://www.acmicpc.net/problem/23845
code
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int dollcount[200001];
int main()
{
long long N, Q = 0, cnt = 0;
long long answer = 0;
cin >> N;
vector<int> matryoshka(N);
for (int i = 0; i < N; i++)
{
cin >> matryoshka[i];
dollcount[matryoshka[i]]++;
}
sort(matryoshka.begin(), matryoshka.end());
for (int i = 0; i < N; i++)
{
if (dollcount[matryoshka[i]] >= 1)
{
dollcount[matryoshka[i]]--;
Q = matryoshka[i];
cnt = 1;
for (int j = matryoshka[i] + 1;; j++)
{
if (dollcount[j] >= 1)
{
Q = j;
dollcount[j]--;
cnt++;
}
else
{
answer += Q * cnt;
break;
}
}
}
}
cout << answer;
return 0;
}
나는 내림차순으로 해서 풀려고했는데, 블로그보고 오름차순으로 순서대로 하려니까 쉽게되더라....