#gsk0001. Zcx and the Guns (Zcx 与枪)
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 guns on the battlefield. Each gun () has a firepower and an original distance from Zcx's starting position.
Zcx can pick up guns one by one. He is given an initial distance limit : he can only pick up a gun whose current distance does not exceed ; otherwise he will be killed by other competitors.
Once Zcx picks up a gun , his chance of getting the remaining guns decreases — the current distance of every other unpicked gun increases by (the original distance of gun ). Formally, if the current distance of gun is before the pickup, then after picking up gun :
Initially, the current distance of every gun equals its original distance, i.e., .
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 and , the number of guns and the initial distance limit.
The second line contains integers , the firepower of each gun.
The third line contains integers , 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 3and2 3 1; among all optimal sequences,1 2 3is the lexicographically smallest one.
Limitations
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 | 10 pts | |
| 2 | for all | 20 pts |
| 3 | No additional constraints | 70 pts |