-
Notifications
You must be signed in to change notification settings - Fork 0
/
uva10714.cpp
61 lines (45 loc) · 1.04 KB
/
uva10714.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
#include <limits.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <bitset>
//#include <unordered_map>
using namespace std;
typedef pair<int, int> ii;
#define traverse(c, it) \
for (map<ii, int>::iterator it = c.begin(); it != c.end(); it++)
int N, maxDist;
vector<int> distances;
int cost1(int i) {
return min(distances[i], maxDist - distances[i]);
}
int cost2(int i) {
return maxDist - cost1(i);
}
int main() {
int T;
cin >> T;
while(T--) {
cin >> maxDist >> N;
distances.clear();
distances.resize(N);
for(int i = 0; i < N; i++) {
cin >> distances[i];
}
int minimum = INT_MIN;
int maximum = INT_MIN;
for(int i = 0; i < N; i++) {
minimum = max(minimum, cost1(i));
maximum = max(maximum, cost2(i));
}
cout << minimum << " " << maximum << endl;
}
return 0;
}