-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathG_Construct_the_Sum.cpp
More file actions
42 lines (42 loc) · 857 Bytes
/
Copy pathG_Construct_the_Sum.cpp
File metadata and controls
42 lines (42 loc) · 857 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
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--)
{
long long n, s;
cin >> n >> s;
long long sum = n * (n + 1) / 2;
if (s > sum)
{
cout << -1 << "\n";
continue;
}
vector<int> ans;
for (long long i = n; i >= 1 && s > 0; i--)
{
if (s >= i)
{
ans.push_back((int)i);
s -= i;
}
}
if (s != 0)
cout << -1 << "\n";
else
{
for (size_t i = 0; i < ans.size(); i++)
{
if (i)
cout << ' ';
cout << ans[i];
}
cout << "\n";
}
}
return 0;
}