đề bài: https://drive.google.com/open?id=1WdNc43RNzBk_a4_NV5_KvX9m-YU7Kojh
em code như thế này nhưng test có 2 chữ số đầu trùng nhau hoặc chữ số đầu lớn hơn chữ số thứ 2 thì bị lỗi thời gian nhờ mọi người xem hộ vs ạ:
#include <bits/stdc++.h>
#define ll long long
#define fo(i,a,b) for(long i=a;i<=b;i++)
#define fod(i,a,b) for(long i=a;i>=b;--i)
using namespace std;
string a;
long k,la;
int b;
stack <int> s;
int main()
{
cin>>a>>k;la=a.size();
fo(i,0,la)
{
b=a[i]-'0';
if(s.empty()) s.push(b);
else {
while(!s.empty()&&b-s.top()>0&&k>0)
{
s.pop();
k--;
}
s.push(b);
}
}
while(k>0&&!s.empty());
{
s.pop();
k--;
}
vector <int> res;
while(!s.empty())
{
int t=s.top();
s.pop();
res.push_back(t);
}
fod(i,res.size()-1,0)
cout<<res[i];
}