-
Notifications
You must be signed in to change notification settings - Fork 0
/
1642.cpp
65 lines (56 loc) · 872 Bytes
/
1642.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
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int d[2005], tmp;
void main()
{
int n, x;
while (scanf("%d%d", &n, &x) != EOF)
{
for (int i = 0; i < 2005; i++)
{
d[i] = 0;
}
d[0] = d[2000] = 1;
x += 1000;
d[x] = 2;
for (int i = 0; i < n; i++)
{
scanf("%d", &tmp);
tmp += 1000;
d[tmp] = 1;
}
int la, lb;
for (int i = x; i <= 2000; i++)
{
if (d[i] == 1)
{
la = i;
break;
}
}
for (int i = x; i >= 0; i--)
{
if (d[i] == 1)
{
lb = i;
break;
}
}
if (lb > 1000 || la < 1000)
{
printf("Impossible\n");
continue;
}
int ans = 0;
if (x > 1000)
{
printf("%d %d\n", x - 1000, 1000 - lb + x - lb);
}
else
{
printf("%d %d\n", la - 1000 + la - x, 1000 - x);
}
}
}