Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created August 28, 2016 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/2ab5fd357dd61a264ec918a4191b9d54 to your computer and use it in GitHub Desktop.
Save jianminchen/2ab5fd357dd61a264ec918a4191b9d54 to your computer and use it in GitHub Desktop.
BrontTrousle - HackerRank world code sprint #6 - study code #4
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
/// <summary>
/// https://www.hackerrank.com/contests/world-codesprint-6/challenges/bonetrousle
/// </summary>
class Solution5
{
static void Main(String[] args)
{
TextReader tIn = Console.In;
TextWriter tOut = Console.Out;
int T = int.Parse(tIn.ReadLine());
for (int t = 0; t < T; t++)
{
long[] nkb = tIn.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(p => long.Parse(p)).ToArray();
long N = nkb[0];
long K = nkb[1];
long B = nkb[2];
long[] P = new long[B];
int ix = 0;
while (ix < P.Length && N > 0 && K > 0 && B > 0)
{
long min = B * (B + 1) / 2;
if (N < min) break;
if (N == min)
{
for (int i = 0; i < B; i++) P[ix + i] = i + 1;
N -= min;
break;
}
//long max = (K - B) * B + min;
//if (N > max) break;
P[ix] = Math.Min(K, N - (B - 1) * B / 2);
K = P[ix] - 1;
N -= P[ix];
B--;
ix++;
}
tOut.WriteLine(N > 0 ? "-1" : string.Join(" ", P.Select(p => p.ToString()).ToArray()));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment