[AGM 2022 资格赛] 分裂

Luogu
IDLGP8239
Time1000ms
Memory512MB
DifficultyP5
2022O2优化AGM
你有一个长度为 $n$ 的数组 $a$,你需要将其分成 $K$ 个非空子段,最终的得分为 $\sum_{i=1}^K mx_i^{b_i}-mn_i^{b_i}$,$b_i$ 是给定常数,$mx_i$ 是第 $i$ 段中的最大值,$mn_i$ 为第 $i$ 中的最小值。 你能获得的最大得分为多少? ## Input 第一行两个正整数 $n,K$。 接下来一行 $n$ 个整数表示 $a_i$。 接下来一行 $K$ 个整数表示 $b_i$。 ## Output 一行一个整数,表示答案。 [samples] ## Note #### 数据规模与约定 对于 $100\%$ 的数据,保证 $1\leq K\leq n\leq 5000$,$1\leq a_i\leq 10^5$,$1\leq b_i\leq 3$。 #### 说明 翻译自 [AGM 2022 Qualification Round K Split](https://judge.agm-contest.com/public/problems/11/text)。
Samples
Input #1
10 3
2 6 10 1 5 9 7 2 1 8
3 1 2
Output #1
1079
API Response (JSON)
{
  "problem": {
    "name": "[AGM 2022 资格赛] 分裂",
    "description": {
      "content": "你有一个长度为 $n$ 的数组 $a$,你需要将其分成 $K$ 个非空子段,最终的得分为 $\\sum_{i=1}^K mx_i^{b_i}-mn_i^{b_i}$,$b_i$ 是给定常数,$mx_i$ 是第 $i$ 段中的最大值,$mn_i$ 为第 $i$ 中的最小值。 你能获得的最大得分为多少? ",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 524288
    },
    "difficulty": {
      "LuoguStyle": "P5"
    },
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGP8239"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "你有一个长度为 $n$ 的数组 $a$,你需要将其分成 $K$ 个非空子段,最终的得分为 $\\sum_{i=1}^K mx_i^{b_i}-mn_i^{b_i}$,$b_i$ 是给定常数,$mx_i$ 是第 $i$ 段中的最大值,$mn_i$ 为第 $i$ 中的最小值。\n\n你能获得的最大得分为多少?\n\n## Input\n\n第一行两个正整数 $n,K$。\n\n接下来一行 $n$ 个整数表示 $a_i$...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments