Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

You are given two integer sequences of length Na1,a2,..,aN and b1,b2,..,bN. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal.

Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions simultaneously:

  • Add 2 to ai.
  • Add 1 to bj.

Constraints

  • 1≤N≤10 000
  • 0≤ai,bi≤109 (1≤iN)
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N
a1 a2 .. aN
b1 b2 .. bN

Output

If we can repeat the operation zero or more times so that the sequences a and b become equal, print Yes; otherwise, print No.


Sample Input 1

Copy
3
1 2 3
5 2 2

Sample Output 1

Copy
Yes

For example, we can perform three operations as follows to do our job:

  • First operation: i=1 and j=2. Now we have a={3,2,3}b={5,3,2}.
  • Second operation: i=1 and j=2. Now we have a={5,2,3}b={5,4,2}.
  • Third operation: i=2 and j=3. Now we have a={5,4,3}b={5,4,3}.

Sample Input 2

Copy
5
3 1 4 1 5
2 7 1 8 2

Sample Output 2

Copy
No

Sample Input 3

Copy
5
2 7 1 8 2
3 1 4 1 5

Sample Output 3

Copy
No

如果a[i]>b[i],就需要a[i]-b[i]个b[i] + 1 操作,如果a[i] < b[i],就需要(a[i] - b[i])/2个a[i] + 2操作与其他的b[j] + 1操作进行组合,比如a[i] = 1,b[i] = 6,就需要2个第二种操作,加完后a[i]为5,比6差1,只需要a[i],b[i]同时再做一个操作就可以。根据题意需要第二个操作不少于第一个操作,才能保证两个操作一齐进行。
代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
int n;
long long a[],b[];
long long z,f;
int main()
{
cin>>n;
for(int i = ;i < n;i ++)
{
cin>>a[i];
}
for(int i = ;i < n;i ++)
{
cin>>b[i];
if(b[i] - a[i] < )f += a[i] - b[i];
else if(b[i] - a[i] > )z += (b[i] - a[i]) / ;
}
if(z >= f)cout<<"Yes";
else cout<<"No";
}

AtCoder Petrozavodsk Contest 001 B - Two Arrays的更多相关文章

  1. 【AtCoder】AtCoder Petrozavodsk Contest 001

    A - Two Integers 如果\(X\)是\(Y\)的倍数的话不存在 可以输出\(X \cdot (\frac{Y}{gcd(X,Y)} - 1)\) 代码 #include <bits ...

  2. AtCoder Petrozavodsk Contest 001

    第一场apc,5H的持久战,我当然水几个题就睡了 A - Two Integers Time limit : 2sec / Memory limit : 256MB Score : 100 point ...

  3. AtCoder Petrozavodsk Contest 001 A - Two Integers

    Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement You are given positive ...

  4. AtCoder Grand Contest 001 D - Arrays and Palindrome

    题目传送门:https://agc001.contest.atcoder.jp/tasks/agc001_d 题目大意: 现要求你构造两个序列\(a,b\),满足: \(a\)序列中数字总和为\(N\ ...

  5. Atcoder Grand Contest 001 D - Arrays and Palindrome(构造)

    Atcoder 题面传送门 洛谷题面传送门 又是道思维题,又是道把我搞自闭的题. 首先考虑对于固定的 \(a_1,a_2,\dots,a_n;b_1,b_2,\dots,b_m\) 怎样判定是否合法, ...

  6. AtCoder Grand Contest 001 C Shorten Diameter 树的直径知识

    链接:http://agc001.contest.atcoder.jp/tasks/agc001_c 题解(官方): We use the following well-known fact abou ...

  7. Atcoder Grand Contest 001 F - Wide Swap(拓扑排序)

    Atcoder 题面传送门 & 洛谷题面传送门 咦?鸽子 tzc 来补题解了?奇迹奇迹( 首先考虑什么样的排列可以得到.我们考虑 \(p\) 的逆排列 \(q\),那么每次操作的过程从逆排列的 ...

  8. AtCoder Grand Contest 001

    B - Mysterious Light 题意:从一个正三角形边上一点出发,遇到边和已走过的边则反弹,问最终路径长度 思路:GCD 数据爆long long #pragma comment(linke ...

  9. 【刷题】AtCoder Regular Contest 001

    A.センター採点 题意:给一个只包含1.2.3.4的字符串,求出现次数最多和最少的字符 做法:还能怎么做... #include<bits/stdc++.h> #define ui uns ...

随机推荐

  1. $git学习总结系列(1)——基本用法

    廖雪峰的官方网站:http://www.liaoxuefeng.com/ 本文是学习廖雪峰的官方网站上git教程git基本用法的总结,详细内容可以进入廖雪峰的官方网站查看. 注:本文中的主要内容都是基 ...

  2. Android 使用OpenCV的三种方式(Android Studio)

    http://blog.csdn.net/sbsujjbcy/article/details/49520791 其实最早接触OpenCV是很久很久之前的事了,大概在2013年的5,6月份,当时还是个菜 ...

  3. CMD mysql 备份脚本

    创建.bat文件 echo. echo MySQL数据库备份脚本 echo ***************************** echo. echo 备份日期:%date% echo 备份时间 ...

  4. 20145239杜文超《网络攻防》- MSF基础应用

    20145239杜文超<网络攻防>- MSF基础应用 基础问题回答 1.用自己的话解释什么是exploit,payload,encode? exploit:实现攻击行为的主体,但没有载荷只 ...

  5. JAVA 集成 Ueditor 百度富文本编辑器

    开发环境:一个简单的SpringMVC框架中,用百度富文本编辑器 ueditor 实现图片和文件的上传 官网地址:http://ueditor.baidu.com/website/ 需要使用到的2个文 ...

  6. How to Delete using INNER JOIN with SQL Server?

    https://stackoverflow.com/questions/16481379/how-to-delete-using-inner-join-with-sql-server You need ...

  7. shell脚本:批量修改文件名

    参考链接1:shell脚本:批量修改文件名(删除文件名中字符) 参考链接2:linux shell 字符串操作详解 (长度,读取,替换,截取,连接,对比,删除,位置 ) 参考链接3:每天一个linux ...

  8. js替换字符串中的数字或非数字

    替换字符串中的数字 var text = "abc123"; text=text.replace(/[0-9]/ig,""); 此时得到的text为" ...

  9. IOS 发布被拒 PLA 1.2问题 整个过程介绍 03 个人账户升级公司账户

    根据上一篇文章,提交的邮件,苹果给我回了一封邮件 如下: 您好: 感谢您参与 Apple 开发者计划支持.我是 XXXX,非常荣幸协助您. 我们随时都可以开始将您的个人会员资格迁移到组织会员资格.首先 ...

  10. java应用线上CPU过高问题排查

    1.top 命令,查看占用CPU最高的PID.ps aux|grep PID 进一步确定tomcat进程出现问题.2.ps -mp pid -o THREAD,tid,time显示线程列表3.prin ...