102004: [AtCoder]ABC200 E - Patisserie ABC 2

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $500$ points

Problem Statement

Takahashi, a pastry chef at ABC Confiserie, has decided to make cakes to celebrate AtCoder Beginner Contest 200.

A cake made by Takahashi has three parameters: beauty, taste, and popularity, each of which is represented by an integer between $1$ and $N$ (inclusive).

He has made a cake of beauty $i$, taste $j$, and popularity $k$ for every triple $(i,j,k)\ (1 \le i,j,k \le N)$.
Then, he has arranged these $N^3$ cakes in a row, as follows:

  • The cakes are in ascending order of sum of beauty, taste, and popularity from left to right.
  • For two cakes with the same sum of beauty, taste, and popularity, the cake with the smaller beauty is to the left.
  • For two cakes with the same sum and the same beauty, the cake with the smaller taste is to the left.

Find the beauty, taste, and popularity of the $K$-th cake from the left.

Constraints

  • All values in input are integers.
  • $1 \le N \le 10^6$
  • $1 \le K \le N^3$

Input

Input is given from Standard Input in the following format:

$N$ $K$

Output

Print three integers representing the cake's beauty, taste, popularity, in this order, with spaces in between.


Sample Input 1

2 5

Sample Output 1

1 2 2

The cakes are in the following order:

$(1,1,1),(1,1,2),(1,2,1),(2,1,1),(1,2,2),(2,1,2),(2,2,1),(2,2,2)$.

Here, each triple of integers represents the beauty, taste, and popularity of a cake.


Sample Input 2

1000000 1000000000000000000

Sample Output 2

1000000 1000000 1000000

The values in input may be large.


Sample Input 3

9 47

Sample Output 3

3 1 4

Input

题意翻译

「ABC西点店」的糕点师傅高桥君做了一批蛋糕,以庆祝第 200 场 Atcoder Beginner Contest 的成功举办。 高桥君做的每块蛋糕都有三个参数——「美丽程度」、「美味程度」和「人气」,每个参数都可以用一个 $[1,N]$ 中的整数来表示。 我们以 $i$ 表示「美丽程度」,$j$ 表示「美丽程度」,$k$ 表示「人气」,则每块蛋糕都可以对应一个三元组 $(i, j, k)$。对于每一种可能的三元组,高桥君都做了一块与之对应的蛋糕。 容易发现,高桥君一共做了 $N^3$ 块蛋糕。这之后,高桥君想要对这些蛋糕按照下面的顺序重新排序。 - $i+j+k$ 小的蛋糕优先放在左边。 - 如果上述和相同,$i$ 更小的蛋糕优先放在左边。 - 如果 $i$ 也相同,$j$ 更小的蛋糕优先放在左边。 排好了顺序,现在高桥君想要问问你:从左往右数第 $K$ 块蛋糕的三个参数分别是多少?

加入题单

上一题 下一题 算法标签: