forked from chencorey/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBonetrousle.cpp
More file actions
51 lines (48 loc) · 1.19 KB
/
Bonetrousle.cpp
File metadata and controls
51 lines (48 loc) · 1.19 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
// https://www.hackerrank.com/contests/world-codesprint-6/challenges/bonetrousle
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int cases;
cin >> cases;
for (int i = 0; i<cases; i++)
{
long long n, k, b;
cin >> n >> k >> b;
long long maxposs = 0;
for(long long j = k-b+1; j<=k; j++)
{
maxposs+=j;
if(maxposs>n)break;
}
if (n>maxposs || n<((1 + b)*b) / 2) cout << -1;
else
{
for (long long j = b; j>0; j--)
{
long long curr = 0;
if((j-1)%2==1)
{
if(n%j>j/2) curr = n/j + 1 + (j-1)/2 + 1;
else curr = n/j + (j-1)/2 + 1;
}
else
{
if(n%j>0) curr = n/j + 1 + (j-1)/2;
else curr = n/j + (j-1)/2;
}
//long long curr = ceil(((double)n) / j + ((double)(j - 1) / 2));
n -= curr;
cout << curr;
if (j != 1)cout << " ";
}
}
if (i != cases - 1)
cout << endl;
}
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
return 0;
}