#P1417. 烹调方案

    ID: 2219 远端评测题 1000ms 125MiB 尝试: 1 已通过: 1 显示难度普及+/提高− 上传者: 标签>动态规划 DP排序背包 DP

烹调方案

Background

Thanks to your help, Mars suffered only minimal damage. But gw was too lazy to rebuild his home, so he built a spaceship and headed toward the distant planet Earth. Halfway through the journey, gw realized a serious problem: he was hungry.

gw can still cook, so he took out stored food to fill his stomach. gw hopes to cook the most delicious food within TT time, but the way to calculate deliciousness is unusual, so the desperate gw is asking for your help.

Problem Description

There are nn ingredients. Each ingredient has three attributes, aia_i, bib_i, and cic_i. If ingredient ii is completed at time tt, you gain a deliciousness score of ait×bia_i-t\times b_i. Cooking ingredient ii takes cic_i time.

As everyone knows, gw is not very good at cooking, so you need to design a cooking plan to maximize the deliciousness score. All cooking must be finished within time TT.

Input Format

The first line contains two positive integers TT and nn, representing the time needed to reach Earth and the number of ingredients.

  • The next line contains nn integers, aia_i.
  • The next line contains nn integers, bib_i.
  • The next line contains nn integers, cic_i.

Output Format

Output the maximum deliciousness score.

74 1
502
2
47

408

Hint

  • Constraints:
    • For 40%40\% of the testdata, 1n101 \le n \le 10.
    • For 100%100\% of the testdata, 1n501 \le n \le 50.
    • All numbers are less than 10510^5.
  • Source: adapted by tinylic.

Translated by ChatGPT 5