CF390B.Inna, Dima and Song

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Inna is a great piano player and Dima is a modest guitar player. Dima has recently written a song and they want to play it together. Of course, Sereja wants to listen to the song very much.

A song is a sequence of notes. Dima and Inna want to play each note at the same time. At that, they can play the i-th note at volume v (1 ≤ v ≤ a__i; v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which the i-th note was played on the guitar and the piano must equal b__i. If Dima and Inna cannot play a note by the described rules, they skip it and Sereja's joy drops by 1. But if Inna and Dima play the i-th note at volumes x__i and y__i (x__i + y__i = b__i) correspondingly, Sereja's joy rises by x__i·y__i.

Sereja has just returned home from the university and his current joy is 0. Help Dima and Inna play the song so as to maximize Sereja's total joy after listening to the whole song!

因娜是一位出色的钢琴演奏家,而季马则是一位谦逊的吉他演奏家。季马最近创作了一首歌曲,他们希望一起演奏这首歌曲。当然,谢列雅非常想聆听这首歌曲。

一首歌曲由一系列音符组成。季马和因娜希望同时演奏每一个音符。对于第 ii 个音符,他们可以在钢琴和吉他上均以音量 vv(其中 1≤v≤ai1 \leq v \leq a_i,且 vv 为整数)演奏。为了保持和谐,第 ii 个音符在吉他与钢琴上的演奏音量之和必须恰好等于 bib_i。如果季马和因娜无法按照上述规则演奏某个音符,则跳过该音符,谢列雅的喜悦值减少 11;但如果他们分别以音量 xix_i 和 yiy_i 演奏第 ii 个音符(满足 xi+yi=bix_i + y_i = b_i),则谢列雅的喜悦值增加 xi⋅yix_i \cdot y_i。

谢列雅刚刚从大学回家,他当前的喜悦值为 00。请帮助季马和因娜演奏整首歌曲,使得谢列雅听完全部歌曲后的总喜悦值最大化!

输入格式

The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of notes in the song. The second line contains n integers a__i (1 ≤ a__i ≤ 106). The third line contains n integers b__i (1 ≤ b__i ≤ 106).

输入的第一行包含一个整数 nn(1 ≤ n ≤ 1051 \leq n \leq 10^5)—— 歌曲中音符的数量。
第二行包含 nn 个整数 aia_i(1 ≤ ai ≤ 1061 \leq a_i \leq 10^6)。
第三行包含 nn 个整数 bib_i(1 ≤ bi ≤ 1061 \leq b_i \leq 10^6)。

输出格式

In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.

在一行中输出一个整数——Sereja 听完一首歌后所能感受到的最大快乐值。

输入输出样例

  • 输入#1

    3
    1 1 2
    2 2 3

    输出#1

    4
  • 输入#2

    1
    2
    5

    输出#2

    -1

说明/提示

In the first sample, Dima and Inna play the first two notes at volume 1 (1 + 1 = 2, the condition holds), they should play the last note at volumes 1 and 2. Sereja's total joy equals: 1·1 + 1·1 + 1·2 = 4.

In the second sample, there is no such pair (x, y), that 1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.

在第一个样例中,Dima 和 Inna 以音量 1 演奏前两个音符(1 + 1 = 21 + 1 = 2,满足条件),他们应以音量 1 和 2 演奏最后一个音符。Sereja 的总快乐值为:1⋅1 + 1⋅1 + 1⋅2 = 41·1 + 1·1 + 1·2 = 4。

在第二个样例中,不存在满足 1 ≤ x, y ≤ 21 ≤ x, y ≤ 2 且 x + y = 5x + y = 5 的数对 (x, y)(x, y),因此 Dima 和 Inna 跳过一个音符。Sereja 的总快乐值为 −1-1。

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

首页