-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path489C.cpp
More file actions
53 lines (49 loc) · 735 Bytes
/
489C.cpp
File metadata and controls
53 lines (49 loc) · 735 Bytes
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
#include<bits/stdc++.h>
using namespace std;
bool can_adjust(int length, int sum)
{
return (sum>=0 && sum<=9*length);
}
int main()
{
int length, sum,sum1;
cin>>length>>sum;
sum1 = sum;
if(!can_adjust(length, sum)||(sum==0 && length>1))
{
cout<<"-1 -1";
}
else if(length==1 &&sum==0)
{
cout<<"0 0";
}
else
{
for(int i = 1; i<=length; i++)
{
for(int j = 0; j<=9; j++)
{
if(((i==1 && j>0)||(i>1)) && can_adjust(length-i,sum-j))
{
cout<<j;
sum = sum - j;
break;
}
}
}
cout<<" ";
for(int i = 1; i<=length; i++)
{
for(int j = 9; j>=0; j--)
{
if(can_adjust(length-i,sum1-j))
{
cout<<j;
sum1 = sum1 - j;
break;
}
}
}
}
return 0;
}