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;
}
相关推荐
研☆香9 分钟前
聊一聊前端的常见字 关键字
开发语言·前端·javascript
叩码以求索14 分钟前
浅谈:前序遍历反转法求解N叉树的后序遍历
算法
wuminyu1 小时前
JDK21中虚拟线程和FFM协同实现高并发源码剖析
java·linux·c语言·jvm·c++
草莓橙子碗1 小时前
Claude 使用指南
开发语言·python
longxiaozhang61 小时前
C# Array类:数组其实没那么难
开发语言·c#
北风toto1 小时前
中缀、前缀、后缀表达式
算法·软件设计师
听取WA声一片(无恶意)1 小时前
CSP-J/CSP-S 深度优先搜索(DFS)完全讲义
c++·算法·深度优先
码流怪侠2 小时前
2026年8月GitHub热榜深度拆解:Agent Skills席卷开源圈,一个“技能包“收割5万星
算法·程序员·github
hold?fish:palm2 小时前
30 两两交换链表中的节点
数据结构·算法·链表
互联网中的一颗神经元2 小时前
06. Small 对象分配:mcache 无锁路径
开发语言·golang