算法1
用pair二元组记录,一个first记录i,一个second记录i的数位,
重写cmp,排序输出即可
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
const int N = 1e6+10;
int n,m,a[N];
typedef pair[HTML_REMOVED] PII;
PII p[N];
int get(int x)
{
int s= 0;
while(x){
s+=x%10;
x/=10;
}
return s;
}
bool cmp(PII a,PII b)
{
if(a.second!=b.second){
return a.second<b.second;
}else {
return a.first < b.first;
}
}
int main()
{
cin>>n>>m;
for(int i =0;i<n;i++){
p[i].first=i+1;
p[i].second=get(i+1);
}
sort(p,p+n,cmp);
cout<<p[m-1].first;
return 0;
}