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. Pacemaker详解

    一.前言 云计算与集群系统密不可分,作为分布式计算和集群计算的集大成者,云计算的基础设施必须通过集群进行管理控制,而作为拥有大量资源与节点的集群,必须具备一个强大的集群资源管理器(Cluster sy ...

  2. 我的npm笔记

    本文记录一些npm的使用技巧,主要包括自己常用的命令,做个备忘. NPM 是什么? NPM是NodeJS的包管理工具,现在已经进一步发展,致力于为很多其他平台提供包管理工具,其核心思想就是让包的安装更 ...

  3. ubuntu下make无法安装的问题

    发布时间:2015-10-30 10:51:30来源:linux网站作者:_莫欺少年穷 在帮同学服务器安装环境过程中,发现,make 命令不能使用,提示: The program 'make' is ...

  4. @MarkFan 口语练习录音 20140415 [MDL演讲口语录音]

    Hi,everybody! 今天是2014年4月14日, 现在是晚上十一点零柒分. 一本励志的书,一场振奋人心的演讲,一次推心置腹的谈话, 最多只是在你背后小推你一下,最终决定是否迈出前进的步伐, 以 ...

  5. @MarkFan 口语练习录音 20140401

    Hi,everybody 对于未来,我只梦想最好的情况, 并定下最踏实的计划,而绝不花时间在无谓的担心上, 因为我知道,只要把我对自己的承诺付诸实践, 我的未来将不会只是一个梦…… 这是引用考拉小巫的 ...

  6. awk中使用shell变量

    方法:使用-v参数. 对于多个shell变量使用多个-v 有个关于shell变量中的空格问题:

  7. tcp三次握手过程

    TCP握手协议 在TCP/IP协议中,TCP协议提供可靠的连接服务,采用三次握手建立一个连接.第一次握手:建立连接时,客户端发送syn包(syn=j)到服务器,并进入SYN_SEND状态,等待服务器确 ...

  8. POI技术实现对excel的导出

    需求:客户端传来两个参数,当前页码和每页的条数,根据传来的参数实现对数据的导出 1.导入依赖 <!-- 报表相关 --> <dependency> <groupId> ...

  9. python编程常见小技巧

    #主要是记录常见的小问题以及解决办法 ##1.复制的代码,经常出现TAB和空格不一致的情况 将tab或者空格删除,然后重新打出空格或者tab就可以了: ##2.python读取文件,经常出现的编码en ...

  10. Hadoop心跳机制源码分析

    正文: 一.体系背景 首先和大家说明一下:hadoop的心跳机制的底层是通过RPC机制实现的,这篇文章我只介绍心跳实现的代码,对于底层的具体实现,大家可以参考我的另几篇博客: 1. hadoop的RP ...