(寒假CF) 比赛要

题意:给位数和位数和 求符合要求的最大值和最小值

//想法都有了,可是却没有做粗来(你484傻啊?? ?(?_?)? ??)

Description

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 ms (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 Input

Input

2 15

Output

69 96

Input

3 0

Output

-1 -1
 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<algorithm>
 4 using namespace std;
 5 int main()
 6 {
 7     int m,s,s1,s2,i;
 8     int a[101],b[101];
 9     while(~scanf("%d %d",&m,&s))
10     {
11         int sum=0;
12         if(m==1&&s==0)
13         puts("0 0");
14         else if(s>9*m||s==0)
15         puts("-1 -1");
16         else
17         {
18             s1=s2=s;
19             for(i=m-1;i>=1;i--)
20             {
21                 if(s1>9)
22                 {
23                     a[i]=9;
24                     s1-=9;
25                 }
26                 else if(s1>1)
27                 {
28                     a[i]=s1-1;
29                     s1=1;
30                 }
31                 else if(s1==1)
32                     a[i]=0;
33             }
34             a[0]=s1;
35             for(i=0;i<m;i++)
36             {
37                 if(s2>9)
38                 {
39                     b[i]=9;
40                     s2-=9;
41                 }
42                 else if(s2>0)
43                 {
44                     b[i]=s2;
45                     s2=0;
46                 }
47                 else if(s2==0)
48                     b[i]=0;
49             }
50             for(i=0;i<m;i++)
51             printf("%d",a[i]);
52             printf(" ");
53             for(i=0;i<m;i++)
54             printf("%d",b[i]);
55             printf("\n");
56         }
57     }
58     return 0;
59 }
				
时间: 2024-10-10 13:27:50

(寒假CF) 比赛要的相关文章

【cf比赛记录】Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)

比赛传送门 只能说当晚状态不佳吧,有点头疼感冒的症状.也跟脑子没转过来有关系,A题最后一步爆搜没能立即想出来,B题搜索没有用好STL,C题也因为前面两题弄崩了心态,最后,果然掉分了. A:简单数学 B:数学+排序 C:字符串搜索 A // https://codeforces.com/contest/1277/problem/A /* 题意: 给出一个数,求不大于该数的完美整数的个数(完美整数指全是一个数组成的数字,如:111, 333333, 444444, 9, 8888 ...) 分析:

记第一场cf比赛

比赛感想 本来21:05开始的比赛,结果记成21:30了...晚了25分钟才开始[捂脸] 这次是Educational Round,所以还比较简单. 前两道题一眼看去模拟+贪心,怕错仔细看了好几遍题,很快切掉 第三题,dfs+贪心 一开始想得有点简单,少了几种情况,写代码时才发现问题-- 悲伤地发现 写+调 这道题用了我很长时间-(这叫什么?基础不牢,地动山摇!) 然后,居然只剩40分钟了-- 第四题,啊啊啊! 图论,我的痛! 果断跳过 第五题,额,不就是个线段树么? n<=10 \(^9\)

【cf比赛记录】Codeforces Round #600 (Div. 2)

Codeforces Round #600 (Div. 2) ---- 比赛传送门 昨晚成绩还好,AC A,B题,还能上分(到底有多菜) 补了C.D题,因为昨晚对C.D题已经有想法了,所以补起题来也快.(C题TLE了,D题想用并查集没好) A // http://codeforces.com/contest/1253/problem/A /* 如果YES,则b[i] - a[i] 在一个区间里的差肯定是相同的且不小于0 */ #include<iostream> #include<cst

【cf比赛记录】Educational Codeforces Round 78 (Rated for Div. 2)

比赛传送门 A. Shuffle Hashing 题意:加密字符串.可以把字符串的字母打乱后再从前面以及后面接上字符串.问加密后的字符串是否符合加密规则. 题解:字符串的长度很短,直接暴力搜索所有情况 // https://codeforces.com/contest/1278/problem/A #include<iostream> #include<cstdio> #include<cstring> using namespace std; int T; char

(寒假CF)乐

题意:ekjfkj=output 依此解开密码,得到题意求第n位(本身是素数,同时反过来也是素数的数) 题解:打表 注意:数组开大,反过来的数不能是自己本身 Descriptionqd ucyhf yi q fhycu dkcruh mxeiu huluhiu yi q tyvvuhudj fhycu dkcruh. oekh jqia yi je vydt jxu djx ucyhf. Inputjxu ydfkj sediyiji ev q iydwbu ydjuwuh d (1 ≤ d ≤

(寒假CF)!

题意:给出两组数字,第二组数字代表第一组数字中的第几位.求从那一位开始,后面不同的数的个数 Description Sereja has an array a, consisting of n integers a1, a2, ..., an. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out m integers l1, l2, 

(寒假CF)快

题意:给出一组数字,得到区间[1,a1],[a1+1,a1+a2],[a1+a2+1,a1+a2+a3]..... 再给出一组数字,求这些数字属于第几个区间 注意:记得数组开大,容易超时 DescriptionIt is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pi

(寒假CF)惨淡一点

题解:类似于最大上升子序列 Iahub got bored, so he invented a game to be played on paper. He writes n integers a1, a2, ..., an. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1 ≤ i ≤ j ≤ n) and fli

cf之路,1,Codeforces Round #345 (Div. 2)

 cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....       其实这个应该是昨天就写完的,不过没时间了,就留到了今天.. 地址:http://codeforces.com/contest/651/problem/A A. Joysticks time limit per test 1 second memory limit per test 256