1400*C. Given Length and Sum of Digits...(贪心)

Problem - 489C - Codeforces

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
int m,s,a[110];
signed main(){
	scanf("%d%d",&m,&s);
	if(s>m*9) puts("-1 -1");
	else if(s==0&&m>1) puts("-1 -1");
	else if(s==0&&m==1) puts("0 0");
	else{
		int t=s;
		t-=1;
		a[1]=1;
		for(int i=m;i>=1;i--){
			if(t>=9){
				a[i]+=9;
				t-=9;
			}
			else{
				a[i]+=t;
				break;
			}
		}
		for(int i=1;i<=m;i++) cout<<a[i];
		cout<<" ";
		t=s;
		memset(a,0,sizeof a);
		for(int i=1;i<=m;i++){
			if(t>=9){
				a[i]+=9;
				t-=9;
			}
			else{
				a[i]+=t;
				break;
			}
		}
		for(int i=1;i<=m;i++) cout<<a[i];
	}
	return 0;
}
相关推荐
gugucoding4 分钟前
2. 【Java】搭建Java开发环境
java·开发语言
多加点辣也没关系4 分钟前
JavaScript|第9章:对象 — 基础
开发语言·javascript·ecmascript
2601_9498180911 分钟前
Vector从入门到应用(C++ STL动态数组万字全解
开发语言·c++
alphaTao1 小时前
LeetCode 每日一题 2026/7/6-2026/7/12
算法·leetcode
想吃火锅10051 小时前
【leetcode】56.合并区间js
算法·leetcode·职场和发展
imuliuliang1 小时前
可合并堆在多任务调度中的优势与实现技巧7
算法
学究天人1 小时前
数学公理体系大全:Comprehensive Collection of Mathematical Axiom Systems(卷6)
网络·算法·数学建模·动态规划·几何学·图论·拓扑学
汤米粥1 小时前
Python爬虫中Xpath用法之——normalize-space()
开发语言·python
wabs6661 小时前
关于动态规划【力扣72.编辑距离的思考】
算法·leetcode·动态规划
科技道人1 小时前
记录 设置-显示大小和字体
开发语言·android设置·字体和显示大小