Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e717f82

Browse files
committed
Today ps
1 parent f519f14 commit e717f82

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

‎Baekjoon/Cpp/2812.cpp‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main()
6+
{
7+
ios::sync_with_stdio(false);
8+
cin.tie(nullptr);
9+
cout.tie(nullptr);
10+
int n, k, i, d;
11+
char c;
12+
stack<int> stk, res;
13+
cin >> n >> k;
14+
for (i = 0; i < n; i++)
15+
{
16+
cin >> c;
17+
d = c - '0';
18+
if (i == 0)
19+
{
20+
stk.push(d);
21+
}
22+
else
23+
{
24+
while (!stk.empty() && stk.top() < d && k > 0)
25+
{
26+
stk.pop();
27+
k -= 1;
28+
}
29+
stk.push(d);
30+
}
31+
}
32+
while (!stk.empty())
33+
{
34+
if (k > 0)
35+
{
36+
k -= 1;
37+
}
38+
else
39+
{
40+
res.push(stk.top());
41+
}
42+
stk.pop();
43+
}
44+
while (!res.empty())
45+
{
46+
cout << res.top();
47+
res.pop();
48+
}
49+
return 0;
50+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /