|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#include <string>
#include <vector>
#include <map>
using namespace std;
int n;
map<string,int > music;
map<string, map<int,int> > musiclist;
vector<int> solution(vector<string> genres, vector<int> plays) {
vector<int> answer;
n=plays.size();
for(int i=0;i<n;i++){
music[genres[i]]+=plays[i];
musiclist[genres[i]][i]=plays[i];
}
while(music.size()){
int Size=0;
string genre;
for(auto mu: music){
if(Size<mu.second){
Size=mu.second;
genre=mu.first;
}
}
for(int i=0;i<2;i++){
int pos=-1;
int play=0;
for(auto ml:musiclist[genre]){
if(play<ml.second){
play=ml.second;
pos=ml.first;
}
}
if(pos==-1)
break;
musiclist[genre].erase(pos);
answer.push_back(pos);
}
music.erase(genre);
}
return answer;
}
|
cs |
출처: https://mungto.tistory.com/196
베스트 앨범 C++(해시)[프로그래머스]
문제 주소입니다. https://programmers.co.kr/learn/courses/30/lessons/42579 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁
mungto.tistory.com
'알고리즘 > 프로그래머스' 카테고리의 다른 글
| [c++] 아이템줍기 (BFS) (1) | 2022.09.29 |
|---|---|
| [c++] 1차 비밀지도 (구현) (0) | 2022.09.28 |
| [c++] 단속카메라 (그리디, 탐욕법) (0) | 2022.09.23 |
| [c++] 야근 지수 (1) | 2022.09.23 |
| [c++] 양궁대회 (DFS,완전탐색 택1) (0) | 2022.09.21 |