Cod sursa(job #3127588)
Utilizator | Data | 7 mai 2023 16:41:47 | |
---|---|---|---|
Problema | Branza | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.6 kb |
#include <iostream>
#include <fstream>
#include <stack>
#include <string>
using namespace std;
ifstream fin("../alibaba.in");
ofstream fout("../alibaba.out");
int N, K, k = 0;
string nr, rez;
stack<char> st;
int main() {
fin >> N >> K >> nr;
for(int i = 0; i < N; i++)
{
while(!st.empty() && k < K && st.top() < nr[i])
{
st.pop();
k++ ;
}
st.push(nr[i]);
}
while(k < K)
{
st.pop();
k++ ;
}
while(!st.empty())
{
rez = st.top() + rez;
st.pop();
}
fout << rez;
return 0;
}