codeforces 390B Inna, Dima and Song
来源:互联网 发布:java跨平台 编辑:程序博客网 时间:2024/05/17 11:34
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!
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).
In a single line print an integer — the maximum possible joy Sereja feels after he listens to a song.
31 1 22 2 3
4
125
-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 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;}
- codeforces 390B Inna, Dima and Song
- Codeforces 390B Inna, Dima and Song(贪心)
- CF 390B:Inna, Dima and Song
- codeforces Inna, Dima and Song
- Codeforces Round #229 (Div. 2) B. Inna, Dima and Song
- Codeforces Round #229 (Div. 2) B. Inna, Dima and Song
- Codeforces Round #229 (Div. 2)B. Inna, Dima and Song
- Codeforces Round #229 (Div. 2) B. Inna, Dima and Song
- Codeforces Round #229 (Div. 2)B. Inna, Dima and Song
- 【简单题】-CF-390B-Inna, Dima and Song
- Inna, Dima and Song
- Codeforces_390B_Inna, Dima and Song
- codeforces 374C C. Inna and Dima(DFS)
- codeforces Inna and Dima:好题,记忆化搜索,dfs
- codeforces 374C Inna and Dima (dfs+记忆化)
- C. Inna and Dima----dfs
- CodeForces 374 B. Inna and Nine
- codeforces-#460B Little Dima and Equation
- 常用正则表达式
- 分析iOS Crash文件的3种方法
- Https请求握手验证方式,对相应域名进行认证通过
- iOS9获取所在城市的接口及解析(简单的NSURLSession使用和新的编码方法使用)
- ML—核技巧
- codeforces 390B Inna, Dima and Song
- 工作备忘-钥匙串存储UUID和账号密码
- 开源ImageFilter库v0.4:新增26种图片效果
- maven-jetty-plugin保存文件报错:请求的操作无法在使用用户映射区域打开的文件上执行
- Golang Log 学习笔记
- TCP/IP协议组
- 博客已搬家,有兴趣者请转至http://www.cnblogs.com/shaoting/
- 【leetcode】Convert Sorted Array to Binary Search Tree
- django migrations