Codeforces Round #229 (Div. 2) B. Inna, Dima and Song
2014-02-12 08:45
435 查看
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
Output
Input
Output
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.
唯一的难点也就是找到一定和的最大积
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
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 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.
#include <stdio.h> int a[100001],b[100001]; int main() { int n,i; __int64 imax = 0; scanf ("%d",&n); for (i = 0;i < n;i++) { scanf ("%d",&a[i]); } for (i = 0;i < n;i++) { scanf ("%d",&b[i]); } for (i = 0;i < n;i++) { __int64 tmax; if (a[i] * 2 >= b[i] && b[i] > 1) { if(b[i] % 2) { tmax = b[i] / 2; tmax = tmax * (tmax + 1); }else { tmax = b[i] / 2; tmax *= tmax; } imax += tmax; }else imax--; } printf ("%I64d\n",imax); return 0; }
唯一的难点也就是找到一定和的最大积
相关文章推荐
- Codeforces Round #229 (Div. 2)B. Inna, Dima and Song
- CF 390B:Inna, Dima and Song
- codeforces Inna, Dima and Song
- Codeforces Round #220 (Div. 2)C题:Inna and Dima(记忆化搜索+DP)
- Codeforces Round #208 (Div. 2) A.Dima and Continuous Line
- Codeforces Round #324 (Div. 2) D.Dima and Lisa(哥德巴赫猜想)
- Codeforces Round #234 (Div. 2):B. Inna and New Matrix of Candies
- Codeforces Round #214 (Div. 2) C. Dima and Salad
- Codeforces Round #229 (Div. 2)B. Inna, Dima and Song
- Codeforces Round #208 (Div. 2) Problem B Dima and Text Messages(简单字符串处理)
- Codeforces Round #324 (Div. 2) D. Dima and Lisa 数论 三素数定理
- Codeforces Round #262(div2) B. Little Dima and Equation
- Codeforces Round #208 (Div. 2) Problem A Dima and Continuous Line(暴力)
- Codeforces Round #214 (Div. 2) C. Dima and Salad 背包
- Codeforces Round #262 (Div. 2) B. Little Dima and Equation
- Codeforces Round #229 (Div. 2) A. Inna and Alarm Clock
- Codeforces Round #223 (Div. 2)--A. Sereja and Dima
- 【Codeforces Round 324 (Div 2)D】【miller-rabin素数检验 猜想】Dima and Lisa 奇数拆分成三素数
- Codeforces Round #262 (Div. 2)B. Little Dima and Equation
- Codeforces Round #229 (Div. 2) B. Inna, Dima and Song