-
Notifications
You must be signed in to change notification settings - Fork 0
/
772b.cpp
60 lines (48 loc) · 1.08 KB
/
772b.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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
using vpi = vector<pi>;
using vb = vector<bool>;
void solve() {
ll n;
cin >> n;
vi a(n);
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
vb locmax(n);
for (ll i = 1; i < n - 1; i++) {
if (a[i] > a[i - 1] && a[i] > a[i + 1]) locmax[i] = true;
}
ll sum = 0;
for (ll i = 1; i < n; i++) {
if (locmax[i - 1]) {
if (i != n - 1) {
a[i] = max(a[i - 1], a[i + 1]);
locmax[i - 1] = false;
locmax[i] = false;
locmax[i + 1] = false;
} else {
a[i] = a[i - 1];
locmax[i - 1] = false;
locmax[i] = false;
}
sum++;
}
}
cout << sum << endl;
for (ll i = 0; i < n; i++) {
cout << a[i] << " ";
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin >> t;
while (t--) solve();
return 0;
}