#P9506. [BalkanOI 2018] Homecoming

    ID: 10777 远端评测题 500ms 250MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP2018交互题O2优化BalkanOI(巴尔干半岛)

[BalkanOI 2018] Homecoming

Background

Translated from BalkanOI 2018 Day 1 T2 “Homecoming”. Since Luogu is much slower than loj, the time limit is adjusted from 300 ms to 500 ms.

Problem Description

There are NN courses, numbered from 00 to N1N-1. If you pass course ii, you can earn AiA_i dollars.
There are NN textbooks, numbered from 00 to N1N-1. The price of textbook ii is BiB_i dollars.
If you want to pass course ii, you need to buy the textbooks numbered $i, (i+1) \bmod N, (i+2) \bmod N, \cdots, (i+K-1) \bmod N$. KK is a given constant.
Your goal is to make money rather than pass all courses. Please compute the maximum number of dollars you can earn.

Input Format

See “Interaction”.

Output Format

See “Interaction”.

Hint

Constraints and Limits

Let the sum of NN over all calls to the solve function be SNS_N, and the sum of NKNK be SNKS_{NK}. Then:

  • 1KN2×1061\le K\le N\le 2\times 10^6
  • 1SN2×1061\le S_N\le 2\times 10^6
  • 0Ai,Bi1090\le A_i,B_i\le 10^9

The detailed subtasks and additional limits are shown in the table below.

Subtask ID Additional Limits Score
11 1SN5001\le S_N\le 500 1313
22 1SN50001\le S_N\le 5000 1818
33 1SNK2×1061\le S_{NK}\le 2\times 10^6 3131
44 No additional limits 3838

Translated by ChatGPT 5