luogu#P4985. 反射

反射

Background

Recently,  TimeTraveller \rm \ TimeTraveller\ played a very fun game. By placing energy emitters, he attacks the enemies’ spaceship.

But  TimeTraveller \rm \ TimeTraveller\ is very clumsy and also kind of silly, and he always cannot beat even very easy levels, so he wants you to help him.

Problem Description

The game works like this. You have kk α\alpha-emitter activators. They can activate any kk α\alpha emitters on an initial platform. Each activated α\alpha emitter will shoot an energy beam toward 4545^\circ northeast, with energy value αi\alpha_i. In the field there are nn floating platforms. Some of these platforms have one of two kinds of energy emitters installed: an α\alpha emitter or a β\beta emitter, with the following functions:

  • For an α\alpha emitter: if it is installed on the upper side of the platform, it shoots an energy beam toward 4545^\circ northeast, with energy value αi\alpha_i; if it is installed on the lower side, it shoots an energy beam toward 4545^\circ southeast, with energy value αi\alpha_i.

  • For a β\beta emitter: no matter where it is installed, it shoots energy beams toward both 4545^\circ northeast and 4545^\circ southeast at the same time, with energy value βi\beta_i.

However, emitters on floating platforms do not activate by themselves. They will be activated only when an energy beam hits the platform they are on, and the energy they shoot is the given value. (Note: when a beam hits such a platform, the platform’s emitter will activate only if, on the path the beam traveled to reach this platform, there was no energy provided by the emitter on this platform. Each time it is hit, it shoots once. As in the figure below, emitter 11 shoots to platform 22, activating emitter 22; then one of its beams hits back to platform 11. At this time, emitter 11 will not shoot again (that is, the energy will not be added again).)

At the beginning, you can only activate kk emitters among the α\alpha emitters on the initial platform (these kk are activated one by one, and each can shoot only once, but emitters elsewhere can shoot multiple times).

Abstract the map as a 2D Cartesian coordinate system. The line x=0x=0 is the ground (a beam disappears when it reaches the ground, but if there is a platform on the ground then it hits the platform first). All platforms, including the initial platform, are parallel to the xx-axis. The enemy spaceship can be viewed as a segment parallel to the yy-axis with endpoints (wx,sy)(wx,sy) and (wx,ty)(wx,ty). When a beam hits the spaceship, it takes damage equal to the sum of all energy values on the path that the beam traveled, and then the beam disappears. (A beam hitting other platforms does not reflect; instead, it is absorbed by the platform as energy to activate the emitter.)

Please determine which initial α\alpha emitters to activate so that the damage dealt to the spaceship is maximized, and output this maximum value.

Input Format

The first line contains two positive integers k,nk,n, meaning you can activate kk initial emitters, and there are nn platforms in total.
The second line contains four integers x1,x2,y,vx_1,x_2,y,v, describing the initial platform. On this platform, at every integer coordinate point, there is an α\alpha emitter that can shoot an energy beam with initial energy vv (for example, when x1=1,x2=3,y=1x_1=1,x_2=3,y=1, there are three initial α\alpha emitters at (1,1),(2,1),(3,1)(1,1),(2,1),(3,1)).
The third line contains three integers wx,sy,tywx,sy,ty, describing the position of the enemy spaceship.
The next nn lines each describe one platform in the following formats:

  • 0 xl xr y0\ x_l\ x_r\ y represents an empty platform.
  • 1 xl xr y xp wi 0/11\ x_l\ x_r\ y\ x_p\ w_i\ 0/1 represents an α\alpha emitter at position (xp,y)(x_p,y) on the platform (xl,y)(xr,y)(x_l,y)\sim (x_r,y), with emitted energy wiw_i. The last 00 or 11 indicates whether it is on the upper side or the lower side: 00 means upper side, 11 means lower side.
  • 2 xl xr y xp wi2\ x_l\ x_r\ y\ x_p\ w_i represents a β\beta emitter at position (xp,y)(x_p,y) on the platform (xl,y)(xr,y)(x_l,y)\sim (x_r,y), with emitted energy wiw_i.

Output Format

One line with one integer, the maximum damage value.

1 3
1 2 1 5
8 1 7
1 4 5 3 5 5 0
2 4 5 5 5 5
1 5 6 6 6 5 1

25
1 11
0 2 1 10
17 3 11
0 1 2 6
1 3 5 5 4 30 0
1 4 7 4 6 10 1
2 4 8 7 6 14
1 7 10 2 9 10 0
1 8 11 10 9 14 1
1 11 13 7 12 10 0
2 11 13 5 12 14
1 11 13 1 12 10 0
2 13 14 8 14 6
1 13 15 3 14 10 0

242

Hint

Sample Explanation:

For sample 11, as shown:

The best choice is the orange one with 2525, while the green one is 1010.

For sample 22, as shown:

Only the orange beam can deal 242242; the other two only deal 9898.

Constraints:

  • For 30%30\% of the data: 0n20,1k30\leq n\leq 20,1\leq k\leq 3.
  • For 40%40\% of the data: the total length of all platforms (excluding the spaceship) does not exceed 10610^6.
  • For 60%60\% of the data: 0n200,1k500\leq n\leq 200,1\leq k\leq 50.
  • For 70%70\% of the data: 0n2000,1k20000\leq n\leq 2000,1\leq k\leq 2000.
  • For 100%100\% of the data: 0n20000,0k200000\leq n\leq 20000,0\leq k\leq 20000, coordinates satisfy 0y1090 \leq y\leq 10^9 and 0x1090\leq x\leq 10^9. All energy values are within 01040\sim 10^4. It is guaranteed that every emitter is on some platform, and the length of each platform and the length of the enemy spaceship are at least 11. It is guaranteed that the initial platform length does not exceed 10510^5, and no platforms overlap.
  • There is an additional 20%20\% of testdata with the same constraints as 100%100\%, except n106n\leq 10^6.

The input is large, so a fast input method is recommended.

Translated by ChatGPT 5