forked from Mohammed-Shoaib/Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE0077.cpp
More file actions
36 lines (32 loc) · 730 Bytes
/
E0077.cpp
File metadata and controls
36 lines (32 loc) · 730 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
// Problem Code: ANUARM
#include <iostream>
#include <vector>
#include <cmath>
#include <utility>
#include <algorithm>
using namespace std;
vector<int> theArmy(int N, vector<int> M) {
pair<int, int> mnmx;
vector<int> soldiers(N);
mnmx.first = *min_element(M.begin(), M.end());
mnmx.second = *max_element(M.begin(), M.end());
for (int j=0 ; j < N ; j++)
soldiers[j] = max(abs(mnmx.first - j), abs(mnmx.second - j));
return soldiers;
}
int main() {
int T;
cin >> T;
while (T--) {
int N, M;
cin >> N >> M;
vector<int> results, rounds(M);
for (int i=0 ; i < M ; i++)
cin >> rounds[i];
results = theArmy(N, rounds);
for (int i=0 ; i < N ; i++)
cout << results[i] << " ";
cout << endl;
}
return 0;
}