mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 17:56:28 +00:00
P1750 出栈序列
R65860618
This commit is contained in:
parent
1143dee585
commit
e3f02fa40b
32
Luogu/P1750/P1750.cpp
Normal file
32
Luogu/P1750/P1750.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
const int N = 300005;
|
||||
|
||||
int n, c, l, r, a[N];
|
||||
bool vis[N];
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin >> n >> c;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
}
|
||||
l = 1, r = c;
|
||||
for (int i = 1; i <= n; i++) {
|
||||
int p = std::min_element(a + l, a + r + 1) - a;
|
||||
cout << a[p] << ' ';
|
||||
vis[p] = true;
|
||||
a[p] = std::numeric_limits<int>::max();
|
||||
while (p && vis[p]) p--;
|
||||
l = std::max(p, 1);
|
||||
r = std::min(r + 1, n);
|
||||
}
|
||||
cout << endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user