Problem
You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
Input
The single line of the input contains a pair of integers m, s (1 ≤ m ≤ 100, 0 ≤ s ≤ 900) — the length and the sum of the digits of the required numbers.
Output
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers “-1 -1” (without the quotes).
Examples
input
2 15
output
69 96
input
3 0
output
-1 -1
题目大致意思为:给定数字的位数和各个位数之和 求符合条件下的最大数值和最小数值
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#define ll long long
int a[105], b[105];
using namespace std;
int main()
{
int m, s;//m是位数 s是各位数之和
cin >> m >> s;
if (m == 1 && s == 0)
{
cout << 0 << " " << 0;
}
//如果各位数都为9的情况下仍小于题目给出的各位数之和
//或者在位数不为1的情况下各位数之和为0
//那么不符合题意 输出-1 -1
else if (m * 9 < s || s < 1)
{
cout << -1 << " " << -1;
}
else
{
int x = s;
//从最低位开始找 为了让数字最小 低位都填满9
for (int i = m; i >= 1; i--)
{
a[i] = min(x, 9);
x = x - min(x, 9);
}
if (a[1] == 0)
{
for (int i = 1; i <= m; i++)
{
if (a[i] != 0)
{
a[i] = a[i] - 1;
a[1] = 1;
break;
}
}
}
//从最高位开始找 为了让数字最大 高位都填满9
x = s;
for (int i = 1; i <= m; i++)
{
b[i] = min(x, 9);
x = x - min(x, 9);
}
for (int i = 1; i <= m; i++)
{
cout << a[i];
}
cout << " ";
for (int i = 1; i <= m; i++)
{
cout << b[i];
}
}
return 0;
}