-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2812.cpp
More file actions
43 lines (39 loc) · 790 Bytes
/
2812.cpp
File metadata and controls
43 lines (39 loc) · 790 Bytes
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
// 2812. 크게 만들기
// 2019.05.20
// 그리디 알고리즘, 수학
#include<string>
#include<queue>
#include<iostream>
using namespace std;
deque<char> dq;
int main()
{
int n,k;
cin>>n>>k;
string num;
cin>>num;
string answer="";
// answer[1] = max(number[b1]) (0<=b1<=k)
// answer[2] = max(str[b2]) (b1<b2<k+1)
// 공식 활용
for(int i=0;i<k;i++)
{
while(!dq.empty() && dq.back()<num[i])
{
dq.pop_back();
}
dq.push_back(num[i]);
}
for (int i = k; i<n; i++)
{
while(!dq.empty() && dq.back()<num[i])
{
dq.pop_back();
}
dq.push_back(num[i]);
answer+=dq.front();
dq.pop_front();
}
cout<<answer<<endl;
return 0;
}