Cod sursa(job #2558536)

Utilizator vvvlll50Lazar Vlad vvvlll50 Data 26 februarie 2020 17:13:20
Problema Divk Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream f("trompeta.in");
ofstream g("trompeta.out");
int n,m,val,st[100005],nr,vf;
char s[1000001];
int main()
{f>>n>>m;
 f.get();
 f>>s+1;
 st[++vf]=s[1]-'0';
 for(int i=2;i<=n;i++)
 {val=s[i]-'0';
  if(vf<m&&st[vf]>val)st[++vf]=val;
  else {
        while(vf>0&&st[vf]<val&&vf+(n-i)>m)vf--;
        if(vf<m)st[++vf]=val;
  }
 // for(int j=1;j<=vf;j++)cout<<st[j]<<" ";
 // cout<<endl;
 }

 for(int i=1;i<=vf;i++)g<<st[i];
    return 0;
}