题解:P3487 [POI 2009] ARC-Architects
题意
给出一个序列
分析
很容易想到,如果想要字典序尽可能的大,就要让每次选的数最大,但是为了让子序列的长度为
AC code
#include<bits/stdc++.h>
using namespace std;
int n,k,a[15000005],q[15000005];
int main(){
k=inicjuj(); a[1]=wczytaj(); n=1;
while(a[n]!=0) a[++n]=wczytaj(); n--;
int h=1,t=0,pos=1;
for(int i = 1;i<=n;i++){
while(h<=t&&q[t]<a[i]) t--;
q[++t]=a[i];
if(i==n-k+pos){
wypisz(q[h]); h++;
pos++;
}
}
return 0;
}