-
Notifications
You must be signed in to change notification settings - Fork 0
/
19637.cpp
71 lines (59 loc) · 1.52 KB
/
19637.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main()
{
int N, M;
cin >> N >> M;
vector<string> style(N);
vector<int> power(N);
vector<int> characters(M);
map<int, string> m;
for(int i = 0; i < N; i++) {
cin >> style[i] >> power[i];
}
for(int i = 0; i < M; i++) {
cin >> characters[i];
}
vector<int> newCharacters(M);
newCharacters = characters;
sort(newCharacters.begin(), newCharacters.end());
int i = 0;
int j = 0;
for(int j=0;j<M;j++) {
if(power[i] < newCharacters[j]) {
i++;
j--;
} else {
m[newCharacters[j]] = style[i];
}
}
// m의 내용을 출력
for(int j=0;j<M;j++) {
cout << m[characters[j]] << "\n";
}
// for(const auto &entry : m) {
// cout << "Power: " << entry.first << ", Style: " << entry.second << endl;
// }
}
// int main()
// {
// int N, M;
// cin.tie(0); ios::sync_with_stdio(0);
// cin >> N >> M;
// vector<string> style(N);
// vector<int> power(N);
// for (int i = 0; i < N; i++) {
// cin >> style[i] >> power[i];
// }
// int characters;
// for (int i = 0; i < M; i++) {
// cin >> characters;
// auto upper = upper_bound(power.begin(), power.end(), characters-1); //characters-1 : characters 포함
// int index = distance(power.begin(), upper);
// cout << style[index] << "\n";
// }
// return 0;
// }