Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstring>
- #include <iostream>
- #include <math.h>
- #include <string>
- #include <sstream>
- #include <iomanip>
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctime>
- #include <time.h>
- #include <string.h>
- #include <algorithm>
- #include <queue>
- #include <stack>
- #include <vector>
- #include <map>
- #include <set>
- using namespace std;
- const int off = 1<<19;
- int T[ off*2 ][2];
- int n, k;
- char in[off];
- void fill(){
- scanf("%s", in);
- for( int x = 0; x < n; x++ ){
- T[ off+x ][0] = in[x];
- T[ off+x ][1] = x;
- }
- for( int x = off -1; x > 0; x-- )
- if( T[ x*2 ][0] < T[ x*2+1 ][0] ){
- T[ x ][0] = T[ x*2+1 ][0];
- T[ x ][1] = T[ x*2+1 ][1];
- }else{
- T[ x ][0] = T[ x*2 ][0];
- T[ x ][1] = T[ x*2 ][1];
- }
- }
- pair<int,int> query( int a, int b, int lo = 0, int hi = off, int p = 1 ){
- if( a >= hi || b <= lo )
- return make_pair(-1,-1);
- if( lo >= a && hi <= b ){
- return make_pair(T[p][0],T[p][1]);
- }
- pair<int,int> aa=query( a,b,lo,(lo+hi)/2,p*2),bb=query( a,b,(lo+hi)/2,hi,p*2+1);
- if( aa.first > bb.first )
- return aa;
- else if( aa.first<bb.first )
- return bb;
- else if( aa.second > bb.second )
- return aa;
- else
- return bb;
- }
- int main(){
- scanf("%d %d", &n, &k);
- fill();
- pair<int ,int > t;
- for( int x = 0; x < n; x++ ){
- t = query( x, x+k+1 );
- if( k - t.second+x >= 0 ){
- k-= t.second-x;
- x = t.second;
- }
- printf("%c",in[ x ]);
- }
- putchar('\n');
- }
Add Comment
Please, Sign In to add comment