ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Сборники > Фёдор Меньшиков. Тренировки > задача:


50320 - Random Sorted List

Гость
• Вопросы к жюри (2)

Задачи сборника

• 151. 50560 - Distanca maksimale
• 153. 50368 - Right-most non zero d...
• 155. 50379 - a^b modulus k
• 158. 50404 - Sum of Self Powers
• 30. 50764 - Fast Typing Competition
• 50303 - Pattern
• 50882 - FizzBuzz
• 50308 - IT Knowledge Seminars
• 50320 - Random Sorted List
• 001. 50385 - From m to n
• 002. 50365 - Sum of the numbers f...
• 002. 50452 - Multiplication Table
• 003. 50387 - Passengers in the Train
• 006. 50293 - Sum of odd numbers f...
• 007. 50401 - Sum of Odd Numbers
• 009. 50783 - Numri me i vogel
• 010. 50782 - Max of N integers

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
Problem By Ibrahim Mesecan.

Random Sorted List

For his experiments, your professor wants to use sorted lists with n elements. The list will be produced randomly, but at the same time he needs the list to be sorted in ascending order.

Question: Write a program that that produces random but sorted list where

  • the list has n elements and
  • the difference between any two consecutive list elements is smaller than k (between 0 and k-1)
Note: Nearly all programming languages have a randum number function. For C/C++, you can use rand() function (from stdlib.h library) to produce a random number. For Example, in the statement:
  r = rand()%10;
r will have a random value between 0 and 9.

Input specification
You will be given 2 integers: n, k; where n is between 1 and 5000 and 1 ≤ k ≤ 50.

Output specification
(Assume that the previous number before the first number is 0) Show the sorted list separated by spaces

 Sample Input I   
  10 5
 Sample Input II   
  15 4
 Sample Output I   
  3 5 7 11 11 11 13 16 17 17   
 Sample Output II   
  2 4 7 10 12 14 17 18 20 20 23 23 23 24 25  


Для отправки решений необходимо выполнить вход.

www.contester.ru