Codeforces Round #229 (Div. 2)B. Inna, Dima and Song

B. Inna, Dima and Song
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 ≤ aiv 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 bi. 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 xi and yi (xi + yi = bi) correspondingly, Sereja's joy rises byxi·yi.

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!

Input

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 ai (1 ≤ ai ≤ 106). The third line contains n integers bi (1 ≤ bi ≤ 106).

Output

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

Sample test(s)
input
3
1 1 2
2 2 3
output
4
input
1
2
5
output
-1
Note

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 ≤ 2x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.


解题报告:

此题题意是。两个人都有a[i]的volume,可以在1~a[i]范围内调整。使两个人之和等于b[i]。那么happy值就加两个的乘积,否则就减去一,求最大的happy值。

根据乘法知道,两个数越靠近值就越大。所以如果a[i]*2>=b[i]的话,那么happy值就加上(b[i]/2)*(b[i]-b[i]/2); 如果b[i]==1的话那么不论a[i]为多少,happy值都减去一,因为两个人无法加起来为1。注意结果会超int的范围,需要用long long。代码如下:

#include<iostream>
#include<cstdio>
using namespace std;
long long a[1000005],b[1000005];
int main(){
    long long n,h;
    h=0;
    scanf("%lld",&n);
    for(int i=0;i<n;i++)
        scanf("%lld",&a[i]);
    for(int i=0;i<n;i++)
        scanf("%lld",&b[i]);
    for(int i=0;i<n;i++){
        if(a[i]*2>=b[i]&&b[i]!=1)
            h+=(b[i]/2)*(b[i]-b[i]/2);
        else
            h--;
    }
    printf("%lld\n",h);
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值