-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswimmingpool.cpp
More file actions
44 lines (34 loc) · 780 Bytes
/
swimmingpool.cpp
File metadata and controls
44 lines (34 loc) · 780 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
// NOTE: it is recommended to use this even if you don't understand the following code.
#include <iostream>
#include <fstream>
using namespace std;
int main() {
// uncomment the following lines if you want to read/write from files
ifstream cin("input.txt");
ofstream cout("output.txt");
int N;
cin >> N;
long long P[N], media=0;
P[0] = 0;
for(long long i=0; i<N; i++) {
cin >> P[i];
}
// insert your code here
long long pos, D = 1000000000;
if (N != 2) {
for (int i=1; i<N-1; i++) {
if ((P[i]-P[0]) > (P[N-1]-P[i])) {
pos = P[i] - P[0];
} else {
pos = P[N-1] - P[i];
}
if (pos < D) {
D = pos;
}
}
} else {
D = P[1] - P[0];
}
cout << D << endl;; // print the result
return 0;
}