-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBalanced-Array.c
More file actions
48 lines (42 loc) · 905 Bytes
/
Balanced-Array.c
File metadata and controls
48 lines (42 loc) · 905 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
45
46
47
48
#include <stdio.h>
void printSuitableArray(int bound)
{
int result = 0;
for (int i = bound; i > 0; i -= 2)
{
printf("%d ", i);
result += i;
}
int j = 1;
int temp = j;
for (int i = 0; i < (bound / 2) - 2; i++)
{
printf("%d ", j);
j += 2;
temp += j;
}
printf("%d ", j);
printf("%d\n", result - temp);
}
int main()
{
int numberOfTestCase;
scanf("%d", &numberOfTestCase);
int testCases[numberOfTestCase];
for (int i = 0; i < numberOfTestCase; i++)
{
scanf("%d", &testCases[i]);
if ((testCases[i] / 2) % 2 != 0)
{
printf("NO\n");
}
else
{
printf("YES\n");
printSuitableArray(testCases[i]);
}
}
return 0;
}
//problem-link -> https://codeforces.com/problemset/problem/1343/B
//time-complexity -> O(n^2)