-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC_Given_Length_and_Sum_of_Digits.cpp
126 lines (118 loc) · 2.96 KB
/
C_Given_Length_and_Sum_of_Digits.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <bits/stdc++.h>
using namespace std;
#define int long long
using pii = pair<int, int>;
#define forr(i, n) for (int i = 0; i < n; i++)
#define reforr(i, n) for (int i = n; i >= 0; i--)
#define eqforr(i, a, n) for (int i = a; i <= n; i++)
#define sqforr(i, n) for (int i = 1; i * i <= n; i++)
#define genforr(i, a, b) for (int i = a; i < b; i++)
#define pba push_back
#define popb pop_back
#define popf pop_front
#define allEle(x) (x).begin(), (x).end()
#define allRle(x) (x).rbegin(), (x).rend()
typedef vector<int> vint;
typedef vector<string> vstr;
#define vcstr(vstr, n) forr(i, n) cin >> vstr[i]
#define vcin(vint, n) forr(i, n) cin >> vint[i]
#define vpin(vint) for (auto x : vint) cout << x << " "; cout << endl;
#define vpstr(vstr) for (auto x : vstr) cout << x << " "; cout << endl;
void __print(int x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned int x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char* x) { cerr << '\"' << x << '\"'; }
void __print(const string& x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V>& x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T& x) {
int f = 0;
cerr << '{';
for (auto& i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define debug(x...)
#endif
const int inf = 1e9 + 5;
int binpow(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1)
res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
void solve() {
int n, sum;
cin >> n >> sum;
if (sum == 0) {
if (n == 1) {
cout << "0 0" << endl;
} else {
cout << "-1 -1" << endl;
}
return;
}
int sum1 = sum;
int sum2 = sum;
string minn = "", maxx = "";
for (int i = 0; i < n; i++) {
for (int j = 0; j < 10; j++) {
if (i == 0 && j == 0) continue;
if ((sum1 - j) <= (n - i - 1) * 9) {
minn += (char)('0' + j);
sum1 -= j;
// debug(minn);
break;
}
}
}
// cout << minn << " ";
for (int i = 0; i < n; i++) {
if (sum <= 9) {
maxx += (char)('0' + sum);
sum = 0;
} else {
maxx += (char)('0' + 9);
sum -= 9;
}
}
// cout << sum << endl;
// cout << 9 * n << endl;
if (sum2 > 9 * n) {
cout << "-1 -1" << endl;
} else {
cout << minn << " " << maxx << endl;
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
for (int i = 0; i < t; i++)
solve();
}