-
Notifications
You must be signed in to change notification settings - Fork 0
/
POSPREFS_DEC20A.cpp
62 lines (51 loc) · 1.19 KB
/
POSPREFS_DEC20A.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 <iostream>
using namespace std;
typedef long long ll;
int main() {
ll T;
cin>>T;
while(T--){
ll N,K;
cin>>N>>K;
ll A[N+1], curr_sum=0;
for(int i=0; i<N; i++){
if(i==0)A[i]=1;
else if(i&1){
A[i]=(i+1);
}else{
A[i]=-(i+1);
}
}
if(K <= ((int)(N/2)+1)){
for(int i=0;i<N;i++){
if(A[i]>0)K--;
if(K<0){
A[i]=-(i+1);
}
}
}else{
ll new_k=K - (((int)(N/2)+1));
for(int i=N-1;i>=0;i--){
if(A[i]<0 && new_k > 0){
A[i]=(i+1);
new_k--;
}
}
}
for(int i=0;i<N;i++){
cout<<A[i]<<" ";
}
cout<<'\n';
}
return 0;
}
// 1 -2 -3
// 1 2 -3 -4 -5 -6 -7 -8 -9 -10
// 1 2 -3 4 -5 -6 -7 -8 -9 -10
// 1 2 -3 4 -5 6 -7 -8 -9 -10
// 1 2 -3 4 -5 6 -7 8 -9 -10
// 1 2 -3 4 -5 6 -7 8 -9 10
// 1 2 -3 4 -5 6 -7 8 -9 10
// 1 2 -3 4 -5 6 -7 8 -9 10
// 1 2 -3 4 -5 6 -7 8 -9 10
// 1 2 -3 4 -5 6 -7 8 -9 10