#gsk0001. Zcx and the Guns (Zcx 与枪)

    ID: 3213 传统题 1000ms 15MiB 尝试: 0 已通过: 0 难度: 4 上传者: 标签>基础算法贪心其它技巧位运算排序动态规划背包思维

Zcx and the Guns (Zcx 与枪)

Background

Zcx is a boy who likes playing CF.

He is picking up guns on the battlefield, and you are expected to be his best friend, Gsk, helping him win the game.

Description

There are nn guns on the battlefield. Each gun ii (1≤i≤n1 \le i \le n) has a firepower aia_i and an original distance bib_i from Zcx's starting position.

Zcx can pick up guns one by one. He is given an initial distance limit dd: he can only pick up a gun whose current distance does not exceed dd; otherwise he will be killed by other competitors.

Once Zcx picks up a gun ii, his chance of getting the remaining guns decreases — the current distance of every other unpicked gun jj increases by bib_i (the original distance of gun ii). Formally, if the current distance of gun jj is DjD_j before the pickup, then after picking up gun ii:

Dj←Dj+bi(j≠i)D_j \leftarrow D_j + b_i \quad (j \ne i)

Initially, the current distance of every gun equals its original distance, i.e., Di=biD_i = b_i.

You need to help Zcx choose an order of picking up guns such that the sum of firepower of the guns he picks up is maximized. If there are multiple picking sequences achieving the maximum sum, output the one with the smallest lexicographical order (compare the sequences of gun indices element by element; the first position where they differ decides). If one sequence is a prefix of another, the shorter one is considered lexicographically smaller.

Input

The first line contains two integers nn and dd, the number of guns and the initial distance limit.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n, the firepower of each gun.

The third line contains nn integers b1,b2,…,bnb_1, b_2, \dots, b_n, the original distance of each gun.

The integers in the second and third lines are separated by spaces; they may wrap across multiple lines.

Output

Two lines.

The first line contains an integer, the maximum total firepower Zcx can get.

The second line contains the indices of the guns in the order Zcx picks them up, separated by a single space. If Zcx picks up no gun, output an empty second line.

Samples

5 10
5 8 3 7 6
3 5 2 4 6
16
1 2 3

Sample 1 Explanation

  • Initially, the current distance of every gun equals its original distance, and all of them are ≤ 10.
  • Pick up gun 1 (current distance 3): the distances of guns 2~5 become 8, 5, 7, 9.
  • Pick up gun 2 (current distance 8): the distances of guns 3~5 become 10, 12, 14.
  • Pick up gun 3 (current distance 10): the distances of guns 4 and 5 become 14 and 16, both > 10, so no more guns can be picked up.
  • The total firepower is 5 + 8 + 3 = 16. Other valid sequences that achieve 16 include 2 1 3 and 2 3 1; among all optimal sequences, 1 2 3 is the lexicographically smallest one.

Limitations

  • 1≤n≤1051 \le n \le 10^5
  • 1≤d≤1031 \le d \le 10^3
  • 1≤ai≤1091 \le a_i \le 10^9
  • 1≤bi≤1091 \le b_i \le 10^9

Time limit: 1s. Memory limit: 15 MB for each test case.

It is recommended to use C or C++ to solve this problem.

Subtasks

Subtask Additional constraints Score
1 n≤20n \le 20 10 pts
2 ai=1a_i = 1 for all ii 20 pts
3 No additional constraints 70 pts