-
Notifications
You must be signed in to change notification settings - Fork 0
/
feng_shui_fence.cpp
71 lines (64 loc) · 1.51 KB
/
feng_shui_fence.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
62
63
64
65
66
67
68
69
70
71
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
using namespace std;
int n, m, k,x,i,ans1,ans2;
vector<int> ch1, ch2;
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
cin >> n;
ch1.resize(n);
ch2.resize(n);
for (int i = 0; i < n; i++)
{
cin >> ch1[i];
ch2[i] = ch1[i];
}
if (n == 1)
{
cout << ch1[0];
return 0;
}
else
{
for (int i = 0; i < (n - 1); i = i + 1)
{
if ((ch1[i]<=ch1[i + 1]) && (i % 2 == 0))
{
ans1 += ch1[i + 1] - ch1[i]+1;
ch1[i] = ch1[i + 1] + 1;
}
if ((ch1[i]>=ch1[i + 1])&&((i % 2) == 1))
{
ans1 += ch1[i ] - ch1[i+1]+1;
ch1[i+1] = ch1[i] + 1;
}
if ((ch2[i]<=ch2[i + 1])&&((i % 2) == 1))
{
ans2 += ch2[i + 1] - ch2[i]+1;
ch2[i] = ch2[i + 1] + 1;
}
if ((ch2[i]>=ch2[i + 1])&&((i % 2) == 0))
{
ans2 += ch2[i] - ch2[i + 1]+1;
ch2[i + 1] = ch2[i] + 1;
}
}
if (!(ans1 >= ans2))
{
for (int i = 0; i < n; i++)
cout << ch1[i] << ' ';
}
else
{
for (int i = 0; i < n; i++)
{
cout << ch2[i] << ' ';
}
}
}
}