CF1866G.Grouped Carriages

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Pak Chanek observes that the carriages of a train is always full on morning departure hours and afternoon departure hours. Therefore, the balance between carriages is needed so that it is not too crowded in only a few carriages.

A train contains NN carriages that are numbered from 11 to NN from left to right. Carriage ii initially contains AiA_i passengers. All carriages are connected by carriage doors, namely for each ii (1≤i≤N−11\leq i\leq N-1), carriage ii and carriage i+1i+1 are connected by a two-way door.

Each passenger can move between carriages, but train regulation regulates that for each ii, a passenger that starts from carriage ii cannot go through more than DiD_i doors.

Define ZZ as the most number of passengers in one same carriage after moving. Pak Chanek asks, what is the minimum possible value of ZZ?

帕克·查内克观察到,列车车厢在早晨出发时段和下午出发时段总是满员的。因此,需要对车厢之间的乘客数量进行平衡,以避免仅有少数几个车厢过度拥挤。

一列火车包含 NN 节车厢,从左至右依次编号为 11 到 NN。初始时,第 ii 节车厢有 AiA_i 名乘客。所有车厢之间均通过车厢门相互连通;具体来说,对每个 ii(1≤i≤N−11\leq i\leq N-1),第 ii 节车厢与第 i+1i+1 节车厢之间有一扇双向通行的门。

每名乘客可在车厢间移动,但列车规定:对每个 ii,一名起始于第 ii 节车厢的乘客最多只能穿过 DiD_i 扇门。

定义 ZZ 为移动结束后,单节车厢中乘客数量的最大值。帕克·查内克提出问题:ZZ 的最小可能值是多少?

输入格式

The first line contains a single integer NN (1≤N≤2⋅1051 \leq N \leq 2\cdot10^5) — the number of carriages.

The second line contains NN integers A1,A2,A3,…,ANA_1, A_2, A_3, \ldots, A_N (0≤Ai≤1090 \leq A_i \leq 10^9) — the initial number of passengers in each carriage.

The third line contains NN integers D1,D2,D3,…,DND_1, D_2, D_3, \ldots, D_N (0≤Di≤N−10 \leq D_i \leq N-1) — the maximum limit of the number of doors for each starting carriage.

第一行包含一个整数 NN(1≤N≤2⋅1051 \leq N \leq 2\cdot10^5)——车厢的数量。

第二行包含 NN 个整数 A1,A2,A3,…,ANA_1, A_2, A_3, \ldots, A_N(0≤Ai≤1090 \leq A_i \leq 10^9)——每节车厢初始的乘客数量。

第三行包含 NN 个整数 D1,D2,D3,…,DND_1, D_2, D_3, \ldots, D_N(0≤Di≤N−10 \leq D_i \leq N-1)——每节起始车厢最多允许的车门数量。

输出格式

An integer representing the minimum possible value of ZZ.

表示 ZZ 的最小可能值的整数。

输入输出样例

  • 输入#1

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

    输出#1

    5

说明/提示

One strategy that is optimal is as follows:

  • 55 people in carriage 11 move to carriage 44 (going through 33 doors).
  • 33 people in carriage 55 move to carriage 33 (going through 22 doors).
  • 22 people in carriage 66 move to carriage 55 (going through 11 door).
  • 11 person in carriage 66 moves to carriage 77 (going through 11 door).

The number of passengers in each carriage becomes [2,4,5,5,4,5,4][2,4,5,5,4,5,4].

一种最优策略如下:

  • 车厢 11 中的 55 人移动到车厢 44(经过 33 扇门)。
  • 车厢 55 中的 33 人移动到车厢 33(经过 22 扇门)。
  • 车厢 66 中的 22 人移动到车厢 55(经过 11 扇门)。
  • 车厢 66 中的 11 人移动到车厢 77(经过 11 扇门)。

各车厢中的乘客数变为 [2,4,5,5,4,5,4][2,4,5,5,4,5,4]。

输入解题思路,AI测评打分。不知道怎么写?

首页