-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBonetrousle.cpp
More file actions
64 lines (53 loc) · 1.04 KB
/
Copy pathBonetrousle.cpp
File metadata and controls
64 lines (53 loc) · 1.04 KB
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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <limits>
using namespace std;
int main() {
int trips;
cin >> trips;
std::vector<long> sticks(trips), boxes(trips), allowedBoxes(trips);
for (int t = 0; t < trips; t++)
cin >> sticks[t] >> boxes[t] >> allowedBoxes[t];
for (int t = 0; t < trips; t++)
{
long n=sticks[t], k=boxes[t], b=allowedBoxes[t];
std::vector<long> values(b);
long sum = 0;
long i = 0;
long max = std::numeric_limits<long>::max();
do
{
long maxElem = abs(n - (b * (b - 1) / 2));
if (k < maxElem)
maxElem = k;
if (maxElem > max)
{
break;
}
else if (maxElem == max)
maxElem--;
sum += maxElem;
values[i] = maxElem;
i++;
n -= maxElem;
k--;
b--;
max = maxElem;
} while (i < allowedBoxes[t]);
if (sum == sticks[t])
{
for (int j = 0; j < allowedBoxes[t]; j++)
{
cout << (j > 0 ? " " : "") << values[j];
}
}
else
cout << "-1";
cout << endl;
}
return 0;
}