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. try catch 事务不会滚

    在spring机制中,在配置事务后,如果采用try catch 捕获异常后,因为异常已经被捕获,所以事务不会滚,从而产生许多脏数据.解决办法: 1.在catch中抛出异常,(throw new Run ...

  2. OpenGL学习进程(3)第一课:初始化窗体

        本节是OpenGL学习的第一个课时,下面介绍如何初始化一个窗体:     (1)显示一个有蓝色背景的窗体: #include <GL/glut.h> #include <st ...

  3. Linux Shell基础 Bash常见命令 history、alias命令以及常用快捷键

    概述  shell中常见命令history 历史纪录命令:history 命令格式如下: [root@localhost ~]# history [选项] [历史命令保存文件] -c:清空历史命令: ...

  4. centos磁盘安装与磁盘分区方案

    概述 关于centos分区的相关知识 无论怎么分区并不会影响系统文件目录的布局,如果只分/和swap这两个区 没有 usr , var , etc 等分区,在安装好后文件根目录里依然会有usr , v ...

  5. Js 类型方面的神坑

    你有没有遇见过本来好好的一个数组结果 typeof 出来是个 object 的情况,你有没有遇到过非要写个 typeof x === "undefined" 判断未赋值的情况... ...

  6. Python编程-绑定方法、软件开发

    一.绑定方法与非绑定方法 1.绑定方法 绑定给谁,谁来调用就自动将它本身当作第一个参数传入 (1)绑定到类的方法:用classmethod装饰器装饰的方法. 为类量身定制 类.boud_method( ...

  7. JS兼容各个浏览器的本地图片上传即时预览效果\、

    在firefox\chrome\ie10等浏览器中可以使用HTML5中的内容实现图片即时预览效果,在IE10以下浏览器中使用滤镜来解决图片显示问题. HTML5中的FileReader对象主要是把文件 ...

  8. 超酷Loading进度条

    在线演示 本地下载

  9. ==、equals与hashCode

    ==  首先,得说明java数据类型分为基本数据类型和引用数据类型, 基本数据类型有8种: 浮点型:float(4 byte), double(8 byte) 整型:byte(1 byte), sho ...

  10. 克隆VMware虚拟机

    虚拟机使用过程需要用到多个进行实验.重新安装时间又太长,通过vmware虚拟机自带软件能够很好的快速克隆出完全相同的系统. 环境:关闭VMware,不要在开启状态哦~ 步骤: 选中需要被克隆的系统 菜 ...