-
Notifications
You must be signed in to change notification settings - Fork 0
/
SUM1SEQ.c
51 lines (51 loc) · 845 Bytes
/
SUM1SEQ.c
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
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int arr[100005];
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
ll s;
cin>>n>>s;
long long int max_sum;
max_sum = n*(n-1)/2;
if(s > max_sum || s < -max_sum) puts("No");
else
{
if((n+s)%2==0)
{
int i;
ll csum = 0;
int pre = 0;
for(i=1;i<n;++i)
{
if((s-csum)>pre)
{
pre++;
arr[i]=pre;
csum+=pre;
}
else
{
pre--;
arr[i]=pre;
csum+=pre;
}
}
if(csum == s)
{
puts("0");
for(i=1;i<n;++i)
cout<<arr[i]<<endl;
}
else puts("No");
}
else puts("No");
}
puts("");
}
}