AtCoder Petrozavodsk Contest 001 B - Two Arrays
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
You are given two integer sequences of length N: a1,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≤i≤N)
- 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
3
1 2 3
5 2 2
Sample Output 1
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
5
3 1 4 1 5
2 7 1 8 2
Sample Output 2
No
Sample Input 3
5
2 7 1 8 2
3 1 4 1 5
Sample Output 3
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的更多相关文章
- 【AtCoder】AtCoder Petrozavodsk Contest 001
A - Two Integers 如果\(X\)是\(Y\)的倍数的话不存在 可以输出\(X \cdot (\frac{Y}{gcd(X,Y)} - 1)\) 代码 #include <bits ...
- AtCoder Petrozavodsk Contest 001
第一场apc,5H的持久战,我当然水几个题就睡了 A - Two Integers Time limit : 2sec / Memory limit : 256MB Score : 100 point ...
- AtCoder Petrozavodsk Contest 001 A - Two Integers
Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement You are given positive ...
- AtCoder Grand Contest 001 D - Arrays and Palindrome
题目传送门:https://agc001.contest.atcoder.jp/tasks/agc001_d 题目大意: 现要求你构造两个序列\(a,b\),满足: \(a\)序列中数字总和为\(N\ ...
- Atcoder Grand Contest 001 D - Arrays and Palindrome(构造)
Atcoder 题面传送门 洛谷题面传送门 又是道思维题,又是道把我搞自闭的题. 首先考虑对于固定的 \(a_1,a_2,\dots,a_n;b_1,b_2,\dots,b_m\) 怎样判定是否合法, ...
- AtCoder Grand Contest 001 C Shorten Diameter 树的直径知识
链接:http://agc001.contest.atcoder.jp/tasks/agc001_c 题解(官方): We use the following well-known fact abou ...
- Atcoder Grand Contest 001 F - Wide Swap(拓扑排序)
Atcoder 题面传送门 & 洛谷题面传送门 咦?鸽子 tzc 来补题解了?奇迹奇迹( 首先考虑什么样的排列可以得到.我们考虑 \(p\) 的逆排列 \(q\),那么每次操作的过程从逆排列的 ...
- AtCoder Grand Contest 001
B - Mysterious Light 题意:从一个正三角形边上一点出发,遇到边和已走过的边则反弹,问最终路径长度 思路:GCD 数据爆long long #pragma comment(linke ...
- 【刷题】AtCoder Regular Contest 001
A.センター採点 题意:给一个只包含1.2.3.4的字符串,求出现次数最多和最少的字符 做法:还能怎么做... #include<bits/stdc++.h> #define ui uns ...
随机推荐
- HibernateQL
查询语言---QL(Query Language) NativeSQL-------功能最强大 HQL--Hibernate QL EJB QL (JP QL)---HQL的一个子集 QBC--- ...
- 关于Class.getResourceAsStream
Properties properties = new Properties(); properties.load(new InputStreamReader(CharactorTest.cl ...
- 【HackerRank】Bus Station
有n组好朋友在公交车站前排队.第i组有ai个人.还有一辆公交车在路线上行驶.公交车的容量大小为x,即它可以同时运载x个人. 当车站来车时(车总是空载过来),一些组从会队头开始走向公交车. 当然,同一组 ...
- request模块 一基础部分
一.HTTP请求 通过requests发送网络请求,方法有get post put delete head options import requests r=requests.get(" ...
- 为多个文件夹下的C源代码编写Makefile文件
上一篇文章写了如何为在同一个文件夹下的C源代码,本篇文章为多个文件夹下的C源代码编写Makefile文件. 建立两个文件夹,分别为abs与src.其最终目录结构如下: 1 $ ls * 2 jun.c ...
- Docker 数据收集利器:cadvisor
gitHub地址:https://github.com/google/cadvisor cAdvisor cAdvisor (Container Advisor) provides container ...
- iOS如何获取蓝牙Mac地址
http://macpu.github.io/2015/11/12/iOS%E5%A6%82%E4%BD%95%E8%8E%B7%E5%8F%96%E8%93%9D%E7%89%99Mac%E5%9C ...
- MongoDB快速入门(六)- 更新文档
更新文档 MongoDB的update()和save()方法用于更新文档到一个集合. update()方法将现有的文档中的值更新,而save()方法使用传递到save()方法的文档替换现有的文档. M ...
- HMM简单理解(来自quora&其他网上资料)
转载自quora: 连接:https://www.quora.com/What-is-a-simple-explanation-of-the-Hidden-Markov-Model-algorithm ...
- Eclipse4.2安装样式插件
1.插件地址 http://eclipse-color-theme.github.com/update 点击Eclipse菜单 Help>>Install New Software... ...