codeforces 390B Inna, Dima and Song

来源:互联网 发布:java跨平台 编辑:程序博客网 时间:2024/05/17 11:34
                                                                                                   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 thei-th note at volume v (1 ≤ v ≤ ai;v is an integer) both on the piano and the guitar. They should retain harmony, so the total volume with which thei-th note was played on the guitar and the piano must equalbi. 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 thei-th note at volumes xi andyi(xi + yi = bi) correspondingly, Sereja's joy rises by xi·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 containsn integers ai(1 ≤ ai ≤ 106). The third line containsn 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
31 1 22 2 3
Output
4
Input
125
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 volumes1 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), that1 ≤ x, y ≤ 2, x + y = 5, so Dima and Inna skip a note. Sereja's total joy equals -1.

解题思路:一组组跑就行,注意会超int,用long long存

题目链接:http://codeforces.com/problemset/problem/390/B

代码:

#include <iostream>#include <stdio.h>using namespace std;int a[1000010];    int b[1000010];int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        for(int i=0;i<n;i++)        scanf("%d",&a[i]);        for(int i=0;i<n;i++)        scanf("%d",&b[i]);        long long ans=0;        for(int i=0;i<n;i++)        {            if(b[i]==1||a[i]*2<b[i])            ans--;            else            {                long long cmp=b[i]/2;                long long cmp1=b[i]-cmp;                ans+=(cmp*cmp1);            }        }        cout<<ans<<endl;    }    return 0;}

0 0
原创粉丝点击