C. Given Length and Sum of Digits... time limit per test
1 second memory limit per test
256 megabytes input
standard input output
standard output 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 【Codeforces Round #277.5 (Div. 2) C】 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).
Sample test(s) input
2 15
output
69 96
input
3 0
output
-1 -1
题意:给你m,s两个数,m代表位数,s代表这个数各个位上的数加起来的和,让我们求这样能组成的最大数和最小数,如果不存在则输出-1 -1。 做法:先判断是否存在这样的数,首先判断m*9>s或者(m>1&&s=0)是否成立,如果成立则不存在这样的数。最大值比较好找,从最前位开始每一位取min(s,9),取完之后s-取得值。最小值则要注意一下最前位,从最后一位开始,如果不是最前位则取min(s-1,9),如果是最前位则取min(s,9)。
#include
#include
#include
#include
#include
#include
#include
#include
#include
推荐阅读
- codeforces B. Young Explorers
- codeforces C. Mere Array
- codeforces D. Omkar and Bed Wars
- codeforces C. Omkar and Waterslide
- codeforces B. Omkar and Infinity Clock
- codeforces B. Ternary Sequence
- 题库-CF|【Codeforces Round 370 (Div 2) E】【线段树 等比数列 区间合并】Memory and Casinos 赌场区间[l,r] l进r先出的概率
- 题库-CF|【Codeforces Round 263 (Div 2)C】【贪心 哈弗曼思维】Appleman and Toastman 每个非1size子树延展为2子树的最大权
- Codeforces|Codeforces Round #605 (Div. 3) D. Remove One Element
- Codeforces|Codeforces Round #643 (Div. 2) B.Young Explorers