#P7107. 天选之人

    ID: 5897 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>贪心洛谷原创Special JudgeO2优化鸽笼构造洛谷月赛

天选之人

Description

Curious, Gnar wants to study, in the general case, how many people can end up with the most marks. He prepares mm rolled paper balls for each of the nn participants, for a total of nmnm paper balls, among which exactly kk are marked in advance. Then, after the paper balls are uniformly shuffled, each person draws mm paper balls.

A person has the most marks if and only if no one else has more marks than them. Please help Gnar determine whether it is possible that exactly p\boldsymbol{p} people draw the most marks. Since Gnar likes to get to the bottom of things, if it is possible, you also need to construct how many marked and unmarked paper balls each person draws.

Formally, suppose the ii-th person draws xix_i marked paper balls and yiy_i unmarked paper balls. Your construction must satisfy:

  • xi,yi0x_i, y_i \ge 0, and xi+yi=mx_i + y_i = m.
  • i=1nxi=k\displaystyle \sum_{i = 1}^{n} x_i = k.
  • There are exactly p\boldsymbol{p} distinct indices jj such that xj=maxi=1n{xi}\displaystyle x_j = \max_{i = 1}^{n} \{x_i\}.

Input Format

Input four integers n,m,k,pn, m, k, p, whose meanings are described above.

Output Format

Output YES or NO in the first line (case-insensitive, e.g., yEs / No are both accepted), indicating whether it is possible that exactly pp people draw the most marks.

If the first line is YES, then output nn lines, each containing xi,yix_i, y_i, representing the numbers of marked and unmarked paper balls drawn by each person.

Since the answer may not be unique, this problem uses a Special Judge. Any construction that satisfies the requirements in the statement will be accepted.

3 3 5 2
YES
2 1
2 1
1 2
3 3 3 2
NO
3 3 5 3
NO

Hint

[Sample Explanation #1]

The sample provides one construction that satisfies the conditions.

[Sample Explanation #2]

No matter what, there are only three possible distributions of marks from high to low: {3,0,0}\{3,0,0\}, {2,1,0}\{2,1,0\}, {1,1,1}\{1,1,1\}. The corresponding numbers of people with the most marks are 11, 11, and 33. Therefore, it is impossible to construct a solution with p=2p = 2.


[Constraints and Conventions]

This problem uses bundled testdata. You must pass all test points in a Subtask to receive the score for that Subtask.

  • Subtask #1 (15 points): n,m8n,m \le 8.
  • Subtask #2 (15 points): n,m100n,m \le 100.
  • Subtask #3 (20 points): n,m105n,m \le 10^5.
  • Subtask #4 (10 points): p=1p = 1.
  • Subtask #5 (40 points): no special constraints.

For all testdata, it is guaranteed that 1pn1051 \le p \le n \le {10}^5, 1m1091 \le m \le {10}^9, 0knm0 \le k \le n m.

Translated by ChatGPT 5