Codeforces Round #229 (Div. 2) B. Inna, Dima and Song
来源:互联网 发布:html 图片存进数据库 编辑:程序博客网 时间:2024/05/22 18:30
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 ≤ ai; 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 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!
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).
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 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.
题目是很简单的。。。但是我又给long long 忘了,到了最后还剩半小时的时候才想起来
每次判断是否存在xi yi满足和为bi,若满足,开心度会上升xi*yi(取最大者)
很简单的一个一元二次方程求最大值问题
代码如下:
#include <algorithm>#include <iostream>#include <string>#include <vector>#define maxn 100010using namespace std;int a[maxn],b[maxn];int main(void){ int n; while(cin >> n){ for(int i=0; i<n; ++i) cin >> a[i]; for(int i=0; i<n; ++i) cin >> b[i]; long long joy = 0; for(int i=0; i<n; ++i) if(2*a[i] >= b[i] && b[i]>=2){ long long v = b[i]/2; long long t = b[i]-v; joy = joy + (v*t); } else --joy; cout << joy << endl; } return 0;}
- 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
- codeforces 390B Inna, Dima and Song
- codeforces Inna, Dima and Song
- Codeforces 390B Inna, Dima and Song(贪心)
- CF 390B:Inna, Dima and Song
- Inna, Dima and Song
- Codeforces Round #220 (Div. 2) C. Inna and Dima (记忆化搜索)
- Codeforces Round #220 (Div. 2)C题:Inna and Dima(记忆化搜索+DP)
- Codeforces Round #208 (Div. 2) B. Dima and Text Messages
- Codeforces Round #208 (Div. 2) B Dima and Text Messages
- Codeforces Round #208 (Div. 2) B. Dima and Text Messages
- Codeforces Round #262 (Div. 2)B. Little Dima and Equation
- Codeforces Round #262 (Div. 2) B. Little Dima and Equation
- Codeforces Round #262 (Div. 2) B. Little Dima and Equation
- PHP中通过socket实现聊天功能
- 经典问题总结(三)
- 01背包 HDU2602
- android中的Handler
- PHP简单练习代码
- Codeforces Round #229 (Div. 2) B. Inna, Dima and Song
- linux 初学者常用目录结构学习
- poj1125 (Floyd)
- Java Date and Time Tutorial
- linux内核TCP相关参数解释
- Java高速、多线程虚拟内存
- 微信打飞机重制教程
- 跨平台移动开发phonegap/cordova 3.3全系列教程-条码扫描barcode
- 高级Bash脚本编程指南(31):数学计算命令