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

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 test(s)
input
2 15
output
69 96
input
3 0
output
-1 -1

#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std; bool can(int m, int s)
{
if(s >= 0 && 9*m >= s) return true;
else return false;
}
int main()
{
int m,s;
cin>>m>>s;
if(!can(m,s))
{
cout<<"-1"<<" "<<"-1"<<endl;
return 0;
}
if(m == 1)
{
if(s >= 10)
{
cout<<"-1"<<" "<<"-1"<<endl;
}
else cout<<s<<" "<<s<<endl;
}
else {
if(s == 0) cout<<"-1"<<" "<<"-1"<<endl;
else { string minn, maxn;
int sum = s; for(int i = 1; i <= m; i++)
for(int j = 0; j < 10; j++)
{
if((j > 0 || (j == 0 && i > 1) ) && can(m - i, sum - j))
{
minn += char('0' + j);
sum -= j;
break;
}
} sum = s;
for(int i = 1; i <= m; i++)
for(int j = 9; j >= 0; j--)
{
if(can(m - i, sum - j))
{
maxn += char('0' + j);
sum -= j;
break;
}
} cout<<minn<<" "<<maxn<<endl; }
}
return 0;
}

Codeforces Round #277.5 (Div. 2)(C题)的更多相关文章

  1. Codeforces Round #277.5 (Div. 2) ABCDF

    http://codeforces.com/contest/489 Problems     # Name     A SwapSort standard input/output 1 s, 256 ...

  2. Codeforces Round #277.5 (Div. 2)

    题目链接:http://codeforces.com/contest/489 A:SwapSort In this problem your goal is to sort an array cons ...

  3. Codeforces Round #277.5 (Div. 2) --E. Hiking (01分数规划)

    http://codeforces.com/contest/489/problem/E E. Hiking time limit per test 1 second memory limit per ...

  4. Codeforces Round #277.5 (Div. 2)B——BerSU Ball

    B. BerSU Ball time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  5. Codeforces Round #277.5 (Div. 2)-D. Unbearable Controversy of Being

    http://codeforces.com/problemset/problem/489/D D. Unbearable Controversy of Being time limit per tes ...

  6. 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 ...

  7. Codeforces Round #277.5 (Div. 2)-B. BerSU Ball

    http://codeforces.com/problemset/problem/489/B B. BerSU Ball time limit per test 1 second memory lim ...

  8. Codeforces Round #277.5 (Div. 2)-A. SwapSort

    http://codeforces.com/problemset/problem/489/A A. SwapSort time limit per test 1 second memory limit ...

  9. Codeforces Round #277.5 (Div. 2) A,B,C,D,E,F题解

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud A. SwapSort time limit per test    1 seco ...

随机推荐

  1. php 备份数据库代码(生成word,excel,json,xml,sql)

    单表备份代码: 复制代码代码如下: <?php class Db { var $conn; function Db($host="localhost",$user=" ...

  2. WMS请求GetCapabilities,变成下载mapserv.exe解决办法

    WMS1.1.1和WMS1.3.0两个版本中的几个区别: 1.WMS1.1.1中提供的DescribeLayers.GetStyles等接口在WMS1.3.0中不再提供支持,只提供GetCapabil ...

  3. cmake 版本升级

    1.在网址 https://cmake.org/files/v3.1/下载   cmake-3.1.0.tar.gz 2.解压 3.执行  ./configure 4.执行 make 5. 执行   ...

  4. golang深坑记录

    go深坑:1.gin.context.JSON,如果没有make数组时,数组返回为null,make后,数组为[]2.json.Number转int64类型 datatemp.(json.Number ...

  5. jquery取得iframe中元素的方法

    原文发布时间为:2010-12-27 -- 来源于本人的百度文章 [由搬家工具导入] 收集利用Jquery取得iframe中元素的几种方法 :contents()  $.trim($("if ...

  6. LeetCode OJ-- LRU Cache ***@

    https://oj.leetcode.com/problems/lru-cache/ 涨姿势的一道题,相当于实现一种数据结构,实现最近最少使用数据结构. // 用来记录 前后节点都是什么 类似链表上 ...

  7. LeetCode OJ-- Populating Next Right Pointers in Each Node

    https://oj.leetcode.com/problems/populating-next-right-pointers-in-each-node/ 二叉树遍历的变种:树的节点多了个next指针 ...

  8. AC日记——通往奥格瑞玛的道路 洛谷 P1462

    通往奥格瑞玛的道路 思路: 二分+spfa: 二分最大费用,然后判断只走小于等于二分答案的点是否可以花费小于体力上限的血量: 来,上代码: #include <cstdio> #inclu ...

  9. HDU 5727.Necklace-二分图匹配匈牙利

    好久没写过博客了,把以前的博客补一下. Necklace Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  10. Axisfault faultcode:Server.userException异常

    ---恢复内容开始--- Axisfault faultcode:Server.userException异常 AxisFault faultCode: {http://schemas.xmlsoap ...