For example, if the input number is 24635
, the least number is 23
after deleting any 3 digits.
It\'s not the same as taking the two smalles
#include
#include
#include
#include
#include
#include
#include
#include
#define mod 1000000007
#define ll long long
using namespace std;
bool Compare (pair p1, pair p2) {
if (p1.first < p2.first) {
return true;
}
return false;
}
int main() {
priority_queue , vector >, function, pair ) > > pq (Compare);
int n, k;
cin>>n>>k;
int i = 1;
while (n) {
pq.push(make_pair(n%10, i));
n = n/10;
i++;
}
for(int j =1; j<=k;j++){
pq.pop();
}
int number = pq.top().first;
int index = pq.top().second;
int digit = 1;
pq.pop();
while(!pq.empty()){
int current_index = pq.top().second;
digit = digit * 10;
if(current_index < index) {
number = number * 10 + pq.top().first;
} else {
number = digit * pq.top().first + number;
}
pq.pop();
}
cout<
I solved the question using priority_queue with pair. please let me know if there is any better solution