Big Portal: This is it.This is a 1-0 card in a special sentence .Original Output 0 0output-1-1, it's wrong ,This problem is a hate good greedy, to the big greedyhere is the code
#include <cstdio> #include <cstring> #include <vector>using namespace Std;int n,m;int ans[110];int Main () {scanf ("%d%d", &n,&m); memset (ans,0,sizeof (ans)); if (n>1&&m==0| | m/n>9| | m/n==9&&m%n!=0) {puts (" -1-1"),} else if (n==1&&m==0) {printf ("0 0\n");} else{int min=m; int num=0; while (min>0) {if (min<9) {ans[num++]=min; min=0; } else{ans[num++]=9; min-=9; }}//printf ("num==%d\n", num); if (num==n) {for (int i=n-1;i>=0;i--) printf ("%d", ans[i]); printf (""); } if (num<n) {printf ("1"); for (int i=1;i<n-num;i++) printf ("0"); printf ("%d", ans[num-1]-1); for (int i=0;i<num-1;i++) printf ("9"); printf (""); } if (num>n) {printf ("-1"); } int max=m; int cnt=0; while (cnt<n) {if (max<9&&max>0) {printf ("%d", max); max=0; } else if (max>=9) {printf ("9"); max-=9; } else{printf ("0"); } cnt++; } printf ("\n "); } }
Codeforces Round #277.5 (Div. 2) C Given Length and Sum of Digits ...