Skip to content

Commit c4c4c35

Browse files
16.09.2025 15:40
1 parent 3eedc0e commit c4c4c35

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

1901A Line Trip.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include <iostream>
2+
using namespace std;
3+
int main()
4+
{
5+
int t;
6+
cin >> t;
7+
while (t--)
8+
{
9+
int n, x;
10+
cin >> n >> x;
11+
if (n == 1)
12+
{
13+
int a;
14+
cin >> a;
15+
if (a > 2 * (x - a))
16+
{
17+
cout << a << endl;
18+
}
19+
else
20+
{
21+
cout << 2 * (x - a) << endl;
22+
}
23+
}
24+
else
25+
{
26+
int maks = -1;
27+
int arr[n + 1];
28+
arr[0] = 0;
29+
for (int i = 1; i < n + 1; i++)
30+
{
31+
cin >> arr[i];
32+
}
33+
int last = arr[n];
34+
for (int i = 0; i < n; i++)
35+
{
36+
if (arr[i + 1] - arr[i] > maks)
37+
{
38+
maks = arr[i + 1] - arr[i];
39+
}
40+
}
41+
if (2 * (x - last) > maks)
42+
{
43+
maks = 2 * (x - last);
44+
}
45+
cout << maks << endl;
46+
}
47+
}
48+
return 0;
49+
}

0 commit comments

Comments
 (0)