A9293 | Inna, Dima and Song
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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!
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!
输入格式
The first line of the input contains integer $n$ $(1<=n<=10^{5})$ — the number of notes in the song. The second line contains $n$ integers $a_{i}$ $(1<=a_{i}<=10^{6})$ . The third line contains $n$ integers $b_{i}$ $(1<=b_{i}<=10^{6})$ .
输出格式
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
输入输出样例
输入 #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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted