Advertisement
Anon2005

Cel mai mic numar

Jan 17th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. string s;
  4. int steve[100001],vf;
  5. int main()
  6. {
  7. #ifdef HOME
  8.     freopen("test.in","r",stdin);
  9.     freopen("test.out","w",stdout);
  10. #endif // HOME
  11.     ios_base::sync_with_stdio(false);
  12.     cin.tie(NULL);
  13.     cout.tie(NULL);
  14.     int n,k,i;
  15.     cin>>n>>k>>s;
  16.     for(i=0; i<n; i++)
  17.     {
  18.         while(k&&vf>(s[i]=='0')&&s[i]-'0'<steve[vf])
  19.         {
  20.             vf--;
  21.             k--;
  22.         }
  23.         if(k>=vf&&steve[vf]==0&&s[i]-'0'<steve[1]&&s[i]!='0')
  24.         {
  25.             k-=vf;
  26.             vf=0;
  27.         }
  28.         steve[++vf]=s[i]-'0';
  29.     }
  30.     while(k&&vf)
  31.     {
  32.         k--;
  33.         vf--;
  34.     }
  35.     for(i=1; i<=vf; i++)
  36.         cout<<steve[i];
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement