首页 > 其他分享 >Codeforces Round #277.5 (Div. 2) C

Codeforces Round #277.5 (Div. 2) C

时间:2023-03-03 13:05:50浏览次数:77  
标签:277.5 int printf Codeforces numbers output input Div include

题目: http://codeforces.com/contest/489/problem/C

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<stdio.h>
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<sstream>
#include<time.h>
#include<malloc.h>

using namespace std;

int n,m;
int a[110];

int main ()
{
    while (scanf("%d %d",&n,&m)!=EOF)
    {
        if ( m == 0 )
        {
            if ( n == 1)
                printf("0 0\n");
            else
                printf("-1 -1\n");
        }
        else if ( n*9 < m)
            printf("-1 -1\n");
        else
        {
            {
                memset(a,0,sizeof(a));
                a[n-1] = 1;
                int ans = m-1;
                for(int i=0 ;ans && i<n;i++)
                {
                    while (ans != 0 && a[i]<9)
                    {
                        ans--;
                        a[i]++;
                    }
                }
                for(int i=n-1;i>=0;i--)
                    printf("%d",a[i]);
                printf(" ");
            }
            {
                memset(a,0,sizeof(a));
                a[0]= 1 ;
                int ans = m-1;
                for(int i=0;ans && i<n;i++)
                {
                    while (ans !=0 && a[i]<9)
                    {
                        ans --;
                        a[i]++;
                    }
                }
                for(int i=0 ;i<n;i++)
                    printf("%d",a[i]);
                printf("\n");
            }
        }
    }
    return 0;
}


标签:277.5,int,printf,Codeforces,numbers,output,input,Div,include
From: https://blog.51cto.com/u_15990681/6098461

相关文章

  • Codeforces Round #266 (Div. 2) C
    http://codeforces.com/contest/466/problem/CC.NumberofWaystimelimitpertest2secondsmemorylimitpertest256megabytes......
  • Codeforces Round #271 (Div. 2) A B D
    http://codeforces.com/contest/474A水题枚举每个字符即可A.Keyboardtimelimitpertest2secondsmemorylimitpertest256mega......
  • Codeforces Round #280 (Div. 2) A B C
    http://codeforces.com/contest/492A水题A.VanyaandCubestimelimitpertest1secondmemorylimitpertest256megabytes......
  • Codeforces Round #281 (Div. 2) A B
    http://codeforces.com/contest/493A第一次结构体开二维数组。。。A.VasyaandFootballtimelimitpertest2secondsmemorylimitper......
  • Codeforces Round #850 (Div. 2, based on VK Cup 2022 - Final Round)
    Preface补题,之前由于要准备开学考(其实只是临时抱佛脚罢了),所以好久没写题不过索性学校题目简单,微积分线代C程都满绩了(甚至溢出好多),思政被卡了一分满绩点,而大英不出所料3.7......
  • div水平垂直居中的四种方式
    div水平垂直居中的四种方式让div水平居中的方式,我所知道的就是以下这四种。目录div水平垂直居中的四种方式一、margin二、绝对定位三、子元素绝对定位父元素相对定位四、......
  • Educational Codeforces Round 55 (Rated for Div. 2) G. Petya and Graph 网络流|
    很经典,想记录一下网络流里有一个很典的trick,求最大获利转化成最小损失求最小损失转化成割边求的是max(边权和-边所连接的点权和),考虑把边看成左部点,把点看成右部点刚开......
  • Educational Codeforces Round 144 (Rated for Div. 2)
    链接EducationalCodeforcesRound144(RatedforDiv.2)只会两个题太弱了A题先打表找出一个很长的字符字串然后,用strstr查找找到yes找不到no#include<iostream>......
  • Codeforces 438D The Child and Sequence 势能线段树
    势能线段树|拉线段树题单时发现的这道花神游历各国的骚操作至今让我印象深刻,原来有名字所谓势能,大意就是原本你在高空,操作一点下降一点,势能变少一点..当你落地时,修改......
  • CFR-826-Div-3解题报告
    F.Multi-ColoredSegments题意:数轴上有\(n\)个线段,每个区间有一个颜色\(c\),对于每个线段,求与它颜色不同的线段中与它的最短距离。距离定义为两个线段中的点集最近的......