https://codeforces.com/problemset/problem/489/C

C. Given Length and Sum of Digits...

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

题意:

给定一个数m 和 一个长度s,计算最大和最小在s长度下的十进制各位数和为m的值

注意如果无法生成,即输出两个-1

题解:

有个小坑,在输出最大值时得注意下k 是否为 0

#include<bits/stdc++.h>
using namespace std;
int main()
{
int m, s, i, k;
cin >> m >> s;
if (s < 1 && m>1 || s > m * 9)
cout << -1 << " " << -1 << endl;
else {
for (i = m - 1, k = s; i >= 0; i--) {
int j = max(0, k - 9 * i);
if (j == 0 && i == m - 1 && k) j = 1;
cout << j;
k -= j;
}
cout << ' ';
for (i = m - 1, k = s; i >= 0; i--) {
int j = min(9, k);
cout << j;
k -= j;
}
}
}

C. Given Length and Sum of Digits... (贪心)的更多相关文章

  1. CodeForces 489C Given Length and Sum of Digits... (贪心)

    Given Length and Sum of Digits... 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/F Descr ...

  2. Codeforces Round #277.5 (Div. 2)C——Given Length and Sum of Digits...

    C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ...

  3. codeforces#277.5 C. Given Length and Sum of Digits

    C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ...

  4. CodeForces 489C Given Length and Sum of Digits... (dfs)

    C. Given Length and Sum of Digits... time limit per test 1 second memory limit per test 256 megabyte ...

  5. Codeforces Round #277.5 (Div. 2)-C. Given Length and Sum of Digits...

    http://codeforces.com/problemset/problem/489/C C. Given Length and Sum of Digits... time limit per t ...

  6. B - Given Length and Sum of Digits... CodeForces - 489C (贪心)

    You have a positive integer m and a non-negative integer s. Your task is to find the smallest and th ...

  7. CodeForces 489C (贪心) Given Length and Sum of Digits...

    题意: 找出m位且各个数位数字之和为s的最大和最小整数,不包括前导0(比如说003是非法的),但0是可以的. 分析: 这题是用贪心来做的,同样是m位数,前面的数字越大这个数就越大. 所以写一个can( ...

  8. Codeforces 489C Given Length and Sum of Digits...

    m位长度,S为各位的和 利用贪心的思想逐位判断过去即可 详细的注释已经在代码里啦~ //#pragma comment(linker, "/STACK:16777216") //f ...

  9. Codeforces Round #667 (Div. 3) D. Decrease the Sum of Digits (贪心)

    题意:给你一个正整数\(n\),每次可以对\(n\)加一,问最少操作多少次是的\(n\)的所有位数之和不大于\(s\). 题解:\(n\)的某个位置上的数进位,意味这后面的位置都可以被更新为\(0\) ...

  10. codeforces 489C.Given Length and Sum of Digits... 解题报告

    题目链接:http://codeforces.com/problemset/problem/489/C 题目意思:给出 m 和 s,需要构造最大和最小的数.满足长度都为 m,每一位的数字之和等于 s. ...

随机推荐

  1. MIGO配置过账后自动打印

    1.业务需求 本文档介绍,当MIGO发货过账时,自动打印自开发表格. 2.打印程序 复制标准配置中调用的程序和子例程,到新的程序(路径可参考下文系统配置) 只用复制子例程entry_wa01即可,参考 ...

  2. PLC 和Modbus/串口设备现场总线通信及短信报警解决方案

    在实现 Modbus 设备与 PROFIBUS DP 协议 PLC 通讯的同时可以在手机端实时的接收报警短信,使客户足不出户了解设备与 PLC 的状态,及时处理现场中的问题. 系统组成 Modbus ...

  3. STM32一个定时器输出四路不同频率和占空比PWM波的方法

    一般来说,一个定时器输出4路频率相同.占空比不同的PWM波是比较容易的,使用PWM模式即可实现.如果说是输出4路频率不同.占空比不同的PWM就没有现成的模式,是不是无法实现了呢?答案肯定是" ...

  4. java String字符串总结

    这里我们将总结字符串相关的知识,除了总结String的API用法,同时我们还会总结一些相关的知识点,包括字符串常量池.StringBuffer.StringBuilder,以及equals和==的用法 ...

  5. [ABC274Ex] XOR Sum of Arrays

    section> Problem Statement For sequences $B=(B_1,B_2,\dots,B_M)$ and $C=(C_1,C_2,\dots,C_M)$, eac ...

  6. Rong晔大佬教程学习(1):背景与项目设计目标

    riscv实际上是一种ISA的指令集,而处理器的设计的基本结构是不变的(如下所示),其区别在于所选用的指令集的类型,一般有ARM.RISCV.MIPS等,采用了不同的引擎,那么车的外观.系统等也会随之 ...

  7. jenkins安装部署、主从架构、slave镜像、K8S对接

    介绍 CI/CD工具,自动化持续集成和持续部署,用于构建各种自动化任务. 官方提供了docker镜像https://hub.docker.com/r/jenkins/jenkins 使用Deploym ...

  8. NC65主键含义

    最简单的办法,调用用友的类 import nc.jdbc.framework.generator.SequenceGenerator; IdGenerator idGenerator = new Se ...

  9. cmd命令根据端口号杀进程

    1.根据端口查到进程pid netstat –ano|findstr 端口号 1 2.使用taskkill命令杀死进程 taskkill /pid pid 1 温馨提醒: 1.执行完第一步后,命令行显 ...

  10. Python 猫的 2023 年终回顾

    2023 年是 Python猫 创办的第 5 年,2024 年已经到来了,我们照例做一个简短的年终回顾吧. 1.30000 订阅与 200 原创. 2020 的年终总结时,公众号订阅数刚破 20000 ...