Codeforces-489C-Given Length and Sum of Digits...
2016-09-11 16:45
579 查看
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
贪心吧,求最小的时候从0开始选,不能有前导0,最大的时候从9开始选
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
贪心吧,求最小的时候从0开始选,不能有前导0,最大的时候从9开始选
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> using namespace std; int main() { int m,s; int b[110]; while(scanf("%d%d",&m,&s)!=EOF) { memset(b,0,sizeof(b)); if(s==0) { if(m==1) printf("0 0\n"); else printf("-1 -1\n"); continue; } for(int i=0;i<m;i++) { b[m-i-1]=min(s,9); s-=min(s,9); } if(s) { printf("-1 -1\n"); continue; } int k; for(k=0;!b[k];k++); b[0]++; b[k]--; for(int i=0;i<m;i++) printf("%d",b[i]); printf(" "); b[0]--; b[k]++; for(int i=m-1;i>=0;i--) printf("%d",b[i]); printf("\n"); } return 0; }
相关文章推荐
- Codeforces 489C - Given Length and Sum of Digits...(贪心)
- CodeForces 489C (贪心) Given Length and Sum of Digits...
- codeforces#277.5 C. Given Length and Sum of Digits
- Codeforces #277.5 (Div. 2) C. Given Length and Sum of Digits...(简单贪心)
- codeforces#277.5 C. Given Length and Sum of Digits
- Codeforces - 277.5 (Div. 2)C - Given Length and Sum of Digits...(模拟 or dfs)
- Codeforces Round #277.5 (Div. 2) C. Given Length and Sum of Digits...
- Codeforces Round #277.5 (Div. 2)C——Given Length and Sum of Digits...
- Codeforces Round #277.5 (Div. 2)C. Given Length and Sum of Digits...(贪心)
- CF 277.5 C.Given Length and Sum of Digits.. 构造
- Codeforces Round #277.5 (Div. 2)C. Given Length and Sum of Digits...(贪心)
- codeforces489 C. Given Length and Sum of Digits...【贪心】
- Codeforces Round #277.5 (Div. 2) C. Given Length and Sum of Digits...
- Codeforces Round #277.5(Div. 2) C. Given Length and Sum of Digits...【贪心】
- 【寒江雪】C. Given Length and Sum of Digits
- Codeforces Round #277.5 (Div. 2)-C. Given Length and Sum of Digits...
- C. Given Length and Sum of Digits...
- CF 489 C Given Length and Sum of Digits...(水题)
- Codeforces Round #277.5 (Div. 2)C——Given Length and Sum of Digits...
- Given Length and Sum of Digits...---------cf水题