Problem:
Digit K
At the Aizu Akabeko store, we sell a unique "lottery" called Digit K. Each lottery ticket has $N$ numbers in a row, going from left to right. The numbers written on them are from 1 to 9.
The purchaser of a lottery ticket can eliminate $K$ numbers from these numbers and earn points for the number of $N-K$ numbers remaining, arranged in order from left to right. For example, if $K=3$ and the lottery says 1414213, the player can choose 1, 1, and 2 from the left and eliminate them to earn 4413 points.
Given a sequence of numbers and an integer $K$, write a program that outputs the maximum number of points that can be earned.
Input
The input is given in the following form.
$N$ $K$
$a_1$ $a_2$ ... $a_N$
The first line gives the number of numbers $N$ ($1 \leq N \leq 200,000$) and the integer $K$ ($0 \leq K < N$). The second line gives $N$ numbers $a_i$ ($1 \leq a_i \leq 9$) written in the lottery.
Output
Output the maximum value of points in a line.
Sample Input and Output
Sample Input 1
7 3
1 4 1 4 2 1 3
Sample Output 1
4423
Sample Input 2
4 1
1 1 9 9
Sample Output 2
199

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
using ll = long long;
using namespace std;

int main(){
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	vector<int> B;
	for (int i = 0; i < N; i++) {
		while (!B.empty() && K > 0 && B.back() < A[i]) {
			B.pop_back();
			K--;
		}
	B.push_back(A[i]);
	}
	while (K > 0) {
		B.pop_back();
		K--;
	}
	for (int d : B) cout << d;
	cout <<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 5344
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	
	int N, K;
	cin >> N >> K;
	K = N - K;
	vector<pair<int, int>> A(N);
	rep(i, 0, N) {
		cin >> A[i].first;
		A[i].second = -i - 1;
	}
	
	priority_queue<pair<int, int>> que;
	rep(i, 0, N - K + 1) que.push(A[i]);
	int now = -1;
	rep(i, 0, K) {
		while (true) {
			int idx = -que.top().second - 1;
			if (idx <= now) que.pop();
			else {
				now = idx;
				cout << que.top().first;
				que.pop();
				break;
			}
		}
		
		if (i != K - 1) que.push(A[N - K + i + 1]);
	}
	cout << '\n';
}
accuracy: 1
time_ms: 20
memory_kb: 6712
final_rank: 7

code_snippet: #include <bits/stdc++.h>
//#include"atcoder/all"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
//using namespace atcoder;
#define all(a) a.begin(),a.end()
//#define int long long
typedef long long ll;
typedef vector<ll> vi;
typedef pair<int,int> P;
typedef pair<P,P> PP;
//const int inf=1ll<<55;
const ll mod=1000000007;
int a[200006];

struct RMQ{
	vector<P>node;
	int n;
	void init(int N){
		n=1;
		while(n<N)n*=2;
		node.resize(2*n);
	}
	void upd(int i,int x){
		i+=n-1;
		node[i]=P(x,i-n+1);
		while(i){
			i=(i-1)/2;
			if(node[i*2+1].first>=node[i*2+2].first)
			node[i]=node[i*2+1];
			else node[i]=node[i*2+2];
		}
	}
	P calc(int a,int b,int k,int l,int r){
		if(r<=a||b<=l)return P(0,0);
		if(a<=l&&r<=b)return node[k];
		P vl=calc(a,b,k*2+1,l,(l+r)/2);
		P vr=calc(a,b,k*2+2,(l+r)/2,r);
		if(vl.first>=vr.first)return vl;
		return vr;
	}
	P get(int a,int b){
		return calc(a,b,0,0,n);
	}
};
RMQ r;
signed main(){
	int n,k;cin>>n>>k;
	r.init(n);
	rep(i,n){
		cin>>a[i];r.upd(i,a[i]);
	}
	
	vector<int>ans;
	int L=0;
	rep(i,n-k){
		int R=k+i;
		P res=r.get(L,R+1);
		ans.push_back(res.first);
		L=res.second+1;
	}
	rep(i,ans.size())cout<<ans[i];cout<<endl;
}
accuracy: 1
time_ms: 30
memory_kb: 8532
final_rank: 13

code_snippet: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
  int n,k;
  cin >> n >> k;
  vector<int>a(n);
  for(int i=0;i<n;i++)cin >> a[i];
  vector<vector<int>>num(9);
  for(int i=0;i<n;i++)num[a[i]-1].emplace_back(i);
  int now=-1;
  k=n-k;
  for(;k--;){
    for(int t=8;t>=0;t--){
      int left=-1,right=num[t].size();
      while(left+1!=right){
        int mokuteki=(left+right)/2;
        if(num[t][mokuteki]<=now)left=mokuteki;
        else right=mokuteki;
      }
      if(right!=num[t].size() && num[t][right]+k<n){
        cout << t+1;
        now=num[t][right];
        break;
      }
    }
  }
  cout << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 5060
final_rank: 9

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    vector<vector<int>> b(10);
    rep(i,n){
        b[a[i]].push_back(i);
    }

    int now = 0;
    int x = k;
    rep(i,n-k){
        for(int j=9;j>=0;j--){
            auto it = lower_bound(b[j].begin(),b[j].end(),now);
            if(it == b[j].end()) continue;
            int id = *it;
            if(id-now<=x){
                x -= id-now;
                now = id+1;
                cout << j;
                break;
            }
        }
    }
    cout << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 5160
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
struct segtree{
	vector<pair<int,int>>seg;
	int sz;
	segtree(int n){
		sz = 1;
		while(sz <= n)sz *= 2;
		seg.resize(sz*2-1,{0,sz+1});
	}
	pair<int,int>f(pair<int,int>a,pair<int,int>b){
		if(a.first > b.first)return a;
		if(a.first < b.first)return b;
		if(a.second < b.second)return a;
		return b;
	}
	pair<int,int> query(int a,int b,int k,int l,int r){
		if(r <= a||b <= l)return {0,sz+1};
		if(a <= l&&r <= b)return seg[k];
		return  f(query(a,b,2*k+1,l,(l+r)/2),query(a,b,2*k+2,(l+r)/2,r));
	}
	pair<int,int> query(int a,int b){
		return query(a,b,0,0,sz);
	}
	void update(int k,pair<int,int> x){
		k += sz-1;
		seg[k] = x;
		while(k > 0){
			k = (k-1)>>1;
			seg[k] = f(seg[2*k+1],seg[2*k+2]);
		}
	}
};
int main(){
	int n,k;
	cin >>n>>k;
	segtree st(n);
	for(int i = 0;i < n;i++){
		int x;
		cin >>x;
		st.update(i,{x,i});
	}
	int a = 0;
	int c = k+1;
	for(int i = 0;i < n-k;i++){
		pair<int,int>d = st.query(a,c);
		c++;
		a = d.second+1;
		cout <<d.first;
	}
	cout <<"\n";
}
accuracy: 1
time_ms: 40
memory_kb: 7228
final_rank: 14

code_snippet: #include<bits/stdc++.h>


signed main() {

	int n, k;

	std::cin >> n >> k;

	std::vector<int>index[10];
	
	for (int i = 1; i <= n; i++) {
		int digit;
		std::cin >> digit;

		index[digit].push_back(i);
	}

	k = n - k;
	std::vector<int>ans;
	for (int i = 1; k>0&&i <= n; i) {
		int j = i;
		for (int d = 9; d > 0; d--) {
			auto idx = std::lower_bound(index[d].begin(), index[d].end(), i);

			if (idx != index[d].end() && n - *idx >= k -1) {
				ans.push_back(d);
				i = *idx + 1;
				k--; break;
			}
		}
	}

	for (auto& i : ans)std::cout << i; std::cout << "\n";
}
accuracy: 1
time_ms: 20
memory_kb: 4768
final_rank: 5

code_snippet: #include <bits/stdc++.h>

int main() {
    int n, k;
    std::cin >> n >> k;
    std::vector<int> a(n);
    std::vector pos(9, std::vector<int>());
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        a[i]--;
        pos[a[i]].push_back(i);
    }
    std::string ans;
    int cur = -1;
    int rem = k;
    while (rem > 0 && (int)ans.size() < n - k) {
        for (int d = 8; d >= 0; d--) {
            auto it = std::upper_bound(pos[d].begin(), pos[d].end(), cur);
            if (it == pos[d].end()) continue;
            int next = *it;
            if (next - cur - 1 <= rem) {
                rem -= next - cur - 1;
                cur = next;
                ans.push_back('1' + d);
                break;
            }
        }
    }
    for (int i = cur + 1; i < n && (int)ans.size() < n - k; i++) ans.push_back('1' + a[i]);
    std::cout << ans << '\n';
}
accuracy: 1
time_ms: 20
memory_kb: 5184
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

// res[i][c] := i 文字目以降で最初に数字 c が登場する index (存在しないときは n)
vector<vector<int> > calc_next(const vector<int> &S) {
    int n = (int)S.size();
    vector<vector<int> > res(n + 1, vector<int>(10, n));
    for (int i = n - 1; i >= 0; --i) {
        for (int j = 0; j < 10; ++j) res[i][j] = res[i + 1][j];
        res[i][S[i]] = i;
    }
    return res;
}

int main(void){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	int N, K;
	cin >> N >> K;
	vector<int> a(N);
	for(int i = 0; i < N; i++) cin >> a[i];
	auto nx = calc_next(a);
	// 上の桁から貪欲に決定させる
	string ans = "";
	int pos = 0;
	for(int i = 0; i < N - K; i++){
		for(int j = 9; j >= 1; j--){
			int np = nx[pos][j];
			if(N - np < N - K - i) continue;
			ans += char(j + '0');
			pos = np + 1;
			break;
		}
	}
	cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 18116
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
int a,b;
cin>>a>>b;
int c[a];
for(int i=0;i<a;i+=1){
    cin>>c[i];
}
int d[9]={-1,-1,-1,-1,-1,-1,-1,-1,-1};
int r=0;
int t=0;
int t2=0;
while(t2<a&&b!=0){
    while(t<a&&r!=511){
        if(d[c[t]-1]==-1){
            d[c[t]-1]=t;
        }
        int s=round(pow(2,c[t]-1));
        if((r/s)%2==0){
            r+=round(pow(2,c[t]-1));
        }
        t+=1;
    }
    r=511;
    int y=8;
    while(b<d[y]-t2||d[y]==-1){
        y-=1;
    }
    r-=round(pow(2,y));
    for(int i=t2;i<d[y]+1;i+=1){
        int w=c[i]-1;
        if(i!=d[y]){
        c[i]=-1;
        b-=1;
        }else{
        t=d[y]+1;
        t2=d[y]+1;    
        }
        d[w]=-1;
        int s=round(pow(2,w));
        if((r/s)%2==1){
            r-=round(pow(2,w));
        }
    }
    d[c[d[y]]]=-1;
}
for(int i=0,t=a-1;i<b;i+=1){
    while(c[t]==-1){
        t-=1;
    }
    c[t]=-1;
}
for(int i=0;i<a;i+=1){
    if(c[i]!=-1){
        cout<<c[i];
    }
}
cout<<endl;
}
accuracy: 1
time_ms: 80
memory_kb: 4068
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
int a,b;
cin>>a>>b;
int c[a];
for(int i=0;i<a;i+=1){
    cin>>c[i];
}
int d[9]={-1,-1,-1,-1,-1,-1,-1,-1,-1};
int r=0;
int t=0;
int t2=0;
while(t2<a&&b!=0){
    while(t<a&&r!=511){
        if(d[c[t]-1]==-1){
            d[c[t]-1]=t;
        }
        int s=round(pow(2,c[t]-1));
        if((r/s)%2==0){
            r+=round(pow(2,c[t]-1));
        }
        t+=1;
    }
    r=511;
    int y=8;
    while(b<d[y]-t2||d[y]==-1){
        y-=1;
    }
    r-=round(pow(2,y));
    for(int i=t2;i<d[y]+1;i+=1){
        int w=c[i]-1;
        if(i!=d[y]){
        c[i]=-1;
        b-=1;
        }else{
        t=d[y]+1;
        t2=d[y]+1;    
        }
        d[w]=-1;
        int s=round(pow(2,w));
        if((r/s)%2==1){
            r-=round(pow(2,w));
        }
    }
    d[c[d[y]]]=-1;
}
for(int i=0;i<a-b;i+=1){
    if(c[i]!=-1){
        cout<<c[i];
    }
}
cout<<endl;
}
accuracy: 0.625
time_ms: 80
memory_kb: 4004
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace::std;

const int N = 200000 + 5;

int n;
int k;
int a[N];

void solve(){
	int l = 1;
	set<pair<int, int>> S;
	for(int i = 1; i <= k; i++) S.emplace(make_pair(-a[i], i));
	for(int i = k + 1; i <= n; i++){
		S.emplace(make_pair(-a[i], i));
		int to = (*S.begin()).second;
		printf("%d", a[to]);
		while(l <= to){
			S.erase(make_pair(-a[l], l));
			l++;
		}
	}
	puts("");
}

int main(){
	scanf("%d %d", &n, &k);
	for(int i = 1; i <= n; i++) scanf("%d", a + i);
	solve();
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 13072
final_rank: 16

code_snippet: #include<bits/stdc++.h>

using namespace std;

#define lol long long
#define INF INT_MAX
#define P pair<int,int>
#define Pci pair<char,int>
#define Pll pair<lol,lol>
#define fi first
#define se second
#define mp(f,s) make_pair(f,s)

// const int mod = (1e9) + 7;
const int mod = 998244353;

int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

// セグ木
struct segment{
    P err = mp(-1,-1);

    vector<P> value;
    int N;

    // コンストラクタ
    segment(int n){
        N = 1;
        while(N < n){
            N *= 2;
        }

        value.resize(N * 2);
        for(int i=0;i<N*2;i++){
            value[i] = err;
        }
    }

    // 値の更新
    // i番目の要素をxに
    void updata(int i,P x){
        i += N - 1;
        value[i] = x;

        while(i > 0){
            i = (i - 1)/2;
            // 大きいほうを取る
            // 等しい場合は左優先
            if(value[i * 2 + 1].fi >= value[i * 2 + 2].fi){
                value[i] = value[i * 2 + 1];
            }else{
                value[i] = value[i * 2 + 2];
            }
        }
    }

    // 特定範囲の最大を探す
    // a,b : 探す範囲
    // l,r : 見てる範囲
    // k   : 実際に見てるとこ
    P quety(int a,int b,int k,int l,int r){
        if(r <= a || b <= l) return(err);
        if(a <= l && r <= b) return(value[k]);

        P c1 = quety(a,b,2 * k + 1,l,(l + r)/2);
        P c2 = quety(a,b,2 * k + 2,(l + r)/2,r);

        if(c1.fi >= c2.fi){
            return(c1);
        }else{
            return(c2);
        }
    }

    // 特定範囲から探す
    P get(int a,int b){
        return(quety(a,b+1,0,0,N));
    }
};

int main(){
    // 2019-5
    // 先頭になりうる数字は先頭からK+1個まで
    // 先頭からK+1番目までの数字の中から最大のやつが先頭にくるように消す
    // k-消した個数,先頭を除外してもう１度

    // 最大を探す部分にセグ木をつかう
    // セグ木にpairを持たせてfirstが最大値,secondがその場所

    int n,k;
    cin>>n>>k;

    segment seg(n);
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        seg.updata(i,mp(a[i],i));
    }

    int left = 0;

    deque<int> ans;

    while(k != 0 && left + k < n){
        P p = seg.get(left,left + k);
        ans.push_back(p.fi);

        k -= p.se - left;

        left = p.se + 1;
    }

    while(!ans.empty()){
        cout<<ans.front();
        ans.pop_front();
    }
    for(int i=left + k;i<n;i++){
        cout<<a[i];
    }
    cout<<"\n";
    return(0);
}
accuracy: 1
time_ms: 30
memory_kb: 8296
final_rank: 11

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0420.cc: Digit K
 */

#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef pair<int,int> pii;

template <typename T>
struct SegTreeMin {
  int e2;
  vector<T> nodes;
  T defv;
  SegTreeMin() {}

  void init(int n, T _defv) {
    defv = _defv;
    for (e2 = 1; e2 < n; e2 <<= 1);
    nodes.assign(e2 * 2, defv);
  }

  T &geti(int i) { return nodes[e2 - 1 + i]; }
  void seti(int i, T v) { geti(i) = v; }

  void setall() {
    for (int j = e2 - 2; j >= 0; j--)
      nodes[j] = min(nodes[j * 2 + 1], nodes[j * 2 + 2]);
  }

  void set(int i, T v) {
    int j = e2 - 1 + i;
    nodes[j] = v;
    while (j > 0) {
      j = (j - 1) / 2;
      nodes[j] = min(nodes[j * 2 + 1], nodes[j * 2 + 2]);
    }
  }

  T min_range(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return defv;
    if (r0 <= i0 && i1 <= r1) return nodes[k];

    int im = (i0 + i1) / 2;
    T v0 = min_range(r0, r1, k * 2 + 1, i0, im);
    T v1 = min_range(r0, r1, k * 2 + 2, im, i1);
    return min(v0, v1);
  }
  T min_range(int r0, int r1) { return min_range(r0, r1, 0, 0, e2); }
};


/* global variables */

int as[MAX_N], bs[MAX_N];
SegTreeMin<pii> st;

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  st.init(n, pii(0, -1));
  for (int i = 0; i < n; i++) st.seti(i, pii(-as[i], i));
  st.setall();

  int m = 0;
  for (int i = 0; i + k < n;) {
    pii e = st.min_range(i, i + k + 1);
    bs[m++] = -e.first;
    k -= e.second - i;
    i = e.second + 1;
  }

  for (int i = 0; i < m; i++) printf("%d", bs[i]);
  putchar('\n');

  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 7760
final_rank: 8

code_snippet: #include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }
template<typename T=ll,size_t N>
array<T,N> arrin(){array<T,N> x;REP(i,N){ x[i]=in<T>(); }return x;}

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

template<typename T>
bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; }
template<typename T>
bool chmin(T& a,T b){ if(a>b){ a=b;return true; }return false; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	ll N=in(),K=in();
	auto A=vecin(N);
	vll F;F.reserve(N);
	vvll M(9);

	REP(i,N){
		M[A[i]-1].push_back(i);
	}

	ll start=0,check=0;
	while(check<K){
		ll maxV=-1,maxI=-1;
		REP(i,9){
			if(M[i].empty()) continue;
			auto res = lower_bound(ALL(M[i]),start);
			if(res!=M[i].end() && *res<=start+K-check){
				maxV=i;
				maxI=*res;
			}
		}
		if(maxV<0){
			start=N;
			break;
		}

		F.push_back(maxV+1);
		if(F.size()>=N-K){
			start=N;
			break;
		}
		check+=maxI-start;
		start = maxI+1;
	}
	for(auto& x:F) cout<<x;
	FOR(i,start,N) cout<<A[i];
	cout<<endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 7140
final_rank: 4

code_snippet: //#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
constexpr lint mod = 1e9 + 7;
#define all(x) begin(x), end(x)
#define bitcount(n) __builtin_popcountll((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzll(x))
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, r) for(int i = int(l); i < int(r); i++)
#define repr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define repr2(i, l, r) for(int i = int(r) - 1; i >= int(l); i--)
constexpr int inf9 = 1e9; constexpr lint inf18 = 1e18;
inline void Yes(bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void array_output(itr start, itr goal){ for(auto i = start; i != goal; i++) cout << (i == start ? "" : " ") << (*i); cout << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(b) return gcd(b, a % b); else return a; }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b){ if(b < a){ a = b; return 1; } return 0; }
inline int has(lint i, int j){ return (i >> j) & 1; }
int dy[4] = {1, 0, -1, 0}; int dx[4] = {0, 1, 0, -1};
bool is_inside(lint y, lint x, lint H, lint W){ return (0 <= y && y < H && 0 <= x && x < W); }

struct io_init {
    io_init() {
        cin.tie(nullptr); cout.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }
} io_init;

int main(){
    int n, k;
    cin >> n >> k;
    k = n - k;
    int a[n];
    rep(i, n) cin >> a[i];
    
    int nxt[n + 1][10];
    rep(i, 10){
        nxt[n][i] = n;
    }
    repr(i, n){
        rep(j, 10){
            nxt[i][j] = nxt[i + 1][j];
        }
        nxt[i][a[i]] = i;
    }
    
    int at = -1;
    rep(c, k){
        repr(i, 10){
            int to = nxt[at + 1][i];
            if(n - to >= k - c){
                cout << i;
                at = to;
                break;
            }
        }
    }
    
    cout << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 11980
final_rank: 10

code_snippet: #ifdef LOGX
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;

using ll=long long;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep2(i,s,n) for(int i=int(s);i<int(n);i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
const int big=1e9+7;
//const int big=998244353;
const char newl='\n';
const int inf=1e9+10;
const ll INF=ll(1e18)+10;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    
    int n,k;
    cin >> n >> k;
    priority_queue<pair<int,int>> q;
    priority_queue<pair<int,int>> to_erase;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    rep(i,k)q.emplace(a[i],-i);
    int al_erased=0;
    rep2(i,k,n){
        while(q.size() && to_erase.size() && q.top()==to_erase.top()){
            q.pop();
            to_erase.pop();
        }
        q.emplace(a[i],-i);
        auto p=q.top();q.pop();
        cout << p.first;
        rep2(j,al_erased,-p.second){
            to_erase.emplace(a[j],-j);
        }
        al_erased=-p.second+1;
    }
    cout << newl;
}
accuracy: 1
time_ms: 30
memory_kb: 8348
final_rank: 12

code_snippet: #include<bits/stdc++.h>
#define rep(a,b,i) for(i=a;i<b;i++)
#define ll long long
#define l1 first
#define l2 second
using namespace std;
typedef pair<int,int>P;
priority_queue<int> qq;
P p[200000];
int main(void)
{
	int i,j,n,k,a[200000],nw,cn,nn,flg[200000]={0},lk,cnt=0;
	cin >> n >> k;
	rep(0,n,i){
		cin >> a[i];
		p[i].l1=-a[i];
		p[i].l2=i;
	}
	nn=k; cn=0;
	sort(p,p+n);
	while(1){
		cnt++;
		rep(0,n,i){
			if(flg[p[i].l2]==0&&p[i].l2>=cn){
				nw=p[i].l2;
				if(nw-cn<=nn){
					//printf("%d <= %d %d\n",nw,nn,cn);
					flg[nw]=1;
					qq.push(-nw);
					nn-=nw-cn;
					cn=nw+1;
					break;
				}
			}
		}
		if(qq.size()==n-k||cnt==10) break;
	}
	while(1){
		lk=-qq.top();
		qq.pop();
		printf("%d",a[lk]);
		if(qq.size()==0) break;
	}
	printf("\n");
	return 0;
}
accuracy: 0.6
time_ms: 20
memory_kb: 6388
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
typedef long long ll;
typedef pair<long long, long long> P;
const long long INF = 1e18;
template <typename T>
void input_arr(vector<T>& A, ll N) {
	for (ll i = 0; i < N; i++) {
		cin >> A[i];
	}
}
template <typename T, typename Q>
void input_arr(vector<pair<T, Q>>& A, ll N) {
	for (ll i = 0; i < N; i++) {
		cin >> A[i].first >> A[i].second;
	}
}
template <typename T>
void input_arr(vector<vector<T>>& A, ll H, ll W) {
	for (ll i = 0; i < H; i++) {
		for (ll j = 0; j < W; j++) {
			cin >> A[i][j];
		}
	}
}
int main() {
	ll N, K; cin >> N >> K;
	vector<ll>A(N); input_arr(A, N);
	vector<vector<ll>>Pos(N, vector<ll>(9, -1));
	for (ll i = 0; i < N; i++) {
		Pos[i][A[i] - 1] = i;
	}
	for (ll i = 1; i < N; i++) {
		for (ll j = 0; j < 9; j++) {
			Pos[i][j] = max(Pos[i][j], Pos[i - 1][j]);
		}
	}
	vector<vector<ll>>B(9);
	for (ll i = 0; i < N; i++) {
		B[A[i] - 1].push_back(i);
	}
	ll pos = -1;
	for (ll i = K; i < N; i++) {
		for (ll j = 8; j >= 0; j--) {
			if (Pos[i][j] > pos) {
				cout << j + 1;
				pos = *upper_bound(B[j].begin(), B[j].end(), pos);
              	break;
			}
		}
	}
	cout << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 26952
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vc = vector<T>;
template<class T> using vvc = vc<vc<T>>;
template<class T> using vvvc = vc<vvc<T>>;
template<class T> using vvvvc = vvc<vvc<T>>;
template<class T> using PQ = priority_queue<T>;
template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>;
using IP = pair<int, int>;
using LP = pair<ll, ll>;
#define all(x) begin(x), end(x)
#define allr(x) rbegin(x), rend(x)
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define rep3(i, m, n) for (int i = (m); (i) < (int)(n); i++)
#define repr(i, n) for (int i = (n) - 1; (i) >= 0; i--)
#define rep3r(i, m, n) for (int i = (n) - 1; (i) >= (int)(m); i--)
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr long long MOD = 998244353;

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int N, K;
    cin >> N >> K;
    vc<int> a(N);
    rep (i, N) cin >> a[i];

    int l = 0;
    vc<int> cnt(10);
    set<int> st;
    string ans;

    rep (i, K) {
        st.insert(a[i]);
        cnt[a[i]]++;
    }
    rep3 (i, K, N) {
        st.insert(a[i]);
        cnt[a[i]]++;
        auto itr = st.end();
        itr--;
        int maxi = *itr;
        ans += (maxi) + '0';
        while (1) {
            if (--cnt[a[l]] == 0) st.erase(a[l]);
            if (a[l++] == maxi) break;
        }
    }

    cout << ans << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4180
final_rank: 1