QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#22580. Ricostruire le somme dei numeri

Statistics

FJ e le sue mucche si divertono con un gioco mentale. Scrivono i numeri da $1$ a $N$ ($1 \le N \le 10$) in un certo ordine, poi sommano i numeri adiacenti per produrre una nuova lista con un numero in meno. Ripetono il procedimento finché rimane un solo numero. Per esempio, una partita, con $N=4$, potrebbe svolgersi così:

3   1   2   4
  4   3   6
    7   9
     16

All’insaputa di FJ, le mucche hanno iniziato un gioco più difficile, in cui cercano di determinare la sequenza iniziale usando soltanto il totale finale e il numero $N$. Purtroppo il gioco supera un po’ le capacità di calcolo mentale di FJ.

Scrivi un programma per aiutare FJ a giocare e a stare al passo con le mucche.

Input

  • Riga 1: due interi separati da uno spazio: $N$ e la somma finale.

Output

  • Riga 1: un ordinamento degli interi $1..N$ che porti alla somma data. Se ci sono più soluzioni, scegli la minima lessicograficamente, cioè quella che mette prima i numeri più piccoli.

Esempi

Input 1

4 16

Output 1

3 1 2 4

Note

Esistono altre sequenze possibili, come $3,2,1,4$, ma $3,1,2,4$ è la minima lessicograficamente.

Problema di Harry Wiggins (2002).

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.