time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There is a beautiful garden of stones in Innopolis.

Its most beautiful place is the nn piles with stones numbered from 11 to nn.

EJOI participants have visited this place twice.

When they first visited it, the number of stones in piles was x1,x2,…,xnx1,x2,…,xn, correspondingly. One of the participants wrote down this sequence in a notebook.

They visited it again the following day, and the number of stones in piles was equal to y1,y2,…,yny1,y2,…,yn. One of the participants also wrote it down in a notebook.

It is well known that every member of the EJOI jury during the night either sits in the room 108108 or comes to the place with stones. Each jury member who comes there either takes one stone for himself or moves one stone from one pile to another. We can assume that there is an unlimited number of jury members. No one except the jury goes to the place with stones at night.

Participants want to know whether their notes can be correct or they are sure to have made a mistake.

Input

The first line of the input file contains a single integer nn, the number of piles with stones in the garden (1≤n≤501≤n≤50).

The second line contains nn integers separated by spaces x1,x2,…,xnx1,x2,…,xn, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the first time (0≤xi≤10000≤xi≤1000).

The third line contains nn integers separated by spaces y1,y2,…,yny1,y2,…,yn, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the second time (0≤yi≤10000≤yi≤1000).

Output

If the records can be consistent output "Yes", otherwise output "No" (quotes for clarity).

Examples
input

Copy
5
1 2 3 4 5
2 1 4 3 5
output

Copy
Yes
input

Copy
5
1 1 1 1 1
1 0 1 0 1
output

Copy
Yes
input

Copy
3
2 3 9
1 7 9
output

Copy
No
Note

In the first example, the following could have happened during the night: one of the jury members moved one stone from the second pile to the first pile, and the other jury member moved one stone from the fourth pile to the third pile.

In the second example, the jury took stones from the second and fourth piles.

It can be proved that it is impossible for the jury members to move and took stones to convert the first array into the second array.

  只要判断一下石头是否增加了就OK。

 #include<bits/stdc++.h>
using namespace std;
#define LL long long
#define inf 0x3f3f3f3f
#define pb push_back
#define pii pair<int,int> int main(){
int n1,n2,n,i,j;
while(scanf("%d",&n)!=EOF){
int s1=,s2=,a;
for(i=;i<=n;++i){
scanf("%d",&a);
s1+=a;
}
for(i=;i<=n;++i){
scanf("%d",&a);
s2+=a;
}
s2<=s1?puts("Yes"):puts("No");
}
return ;
}
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There is an array with n elements a1, a2, ..., an and the number x.

In one operation you can select some i (1 ≤ i ≤ n) and replace element ai with ai & x, where & denotes the bitwise and operation.

You want the array to have at least two equal elements after applying some operations (possibly, none). In other words, there should be at least two distinct indices i ≠ j such that ai = aj. Determine whether it is possible to achieve and, if possible, the minimal number of operations to apply.

Input

The first line contains integers n and x (2 ≤ n ≤ 100 000, 1 ≤ x ≤ 100 000), number of elements in the array and the number to and with.

The second line contains n integers ai (1 ≤ ai ≤ 100 000), the elements of the array.

Output

Print a single integer denoting the minimal number of operations to do, or -1, if it is impossible.

Examples
input

Copy
4 3
1 2 3 7
output

Copy
1
input

Copy
2 228
1 1
output

Copy
0
input

Copy
3 7
1 2 3
output

Copy
-1
Note

In the first example one can apply the operation to the last element of the array. That replaces 7 with 3, so we achieve the goal in one move.

In the second example the array already has two equal elements.

In the third example applying the operation won't change the array at all, so it is impossible to make some pair of elements equal.

  问至少经过几次ai=ai&x的操作能使得数组a中有一个元素至少出现了两次。

如果可以的话只有可能是0/1/2分别判断一下就好了。

 #include<bits/stdc++.h>
using namespace std;
#define LL long long
#define inf 0x3f3f3f3f
#define pb push_back
#define pii pair<int,int>
bool vis1[],vis2[];
int a[];
int main(){
int n,x,i;
while(cin>>n>>x){
memset(vis1,,sizeof(vis1));
memset(vis2,,sizeof(vis2));
bool odd=;
int ans=;
for(i=;i<=n;++i){
scanf("%d",a+i);
if(vis1[a[i]]){
odd=;
}
if(vis1[a[i]&x]||vis2[a[i]]){
ans=;
}
vis1[a[i]]=;
vis2[a[i]&x]=;
}
if(odd){cout<<<<endl;continue;}
if(ans){cout<<ans<<endl;continue;}
memset(vis1,,sizeof(vis1));
for(i=;i<=n;++i){
if(vis1[a[i]&x]){
ans=;
break;
}
vis1[a[i]&x]=;
}
ans?cout<<ans<<endl:cout<<-<<endl;
}
return ;
}
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes.

Strictly speaking, it makes a photo of all points with coordinates (x,y)(x,y), such that x1≤x≤x2x1≤x≤x2 and y1≤y≤y2y1≤y≤y2, where (x1,y1)(x1,y1) and (x2,y2)(x2,y2) are coordinates of the left bottom and the right top corners of the rectangle being photographed. The area of this rectangle can be zero.

After taking the photo, Pavel wrote down coordinates of nn of his favourite stars which appeared in the photo. These points are not necessarily distinct, there can be multiple stars in the same point of the sky.

Pavel has lost his camera recently and wants to buy a similar one. Specifically, he wants to know the dimensions of the photo he took earlier. Unfortunately, the photo is also lost. His notes are also of not much help; numbers are written in random order all over his notepad, so it's impossible to tell which numbers specify coordinates of which points.

Pavel asked you to help him to determine what are the possible dimensions of the photo according to his notes. As there are multiple possible answers, find the dimensions with the minimal possible area of the rectangle.

Input

The first line of the input contains an only integer nn (1≤n≤1000001≤n≤100000), the number of points in Pavel's records.

The second line contains 2⋅n2⋅n integers a1a1, a2a2, ..., a2⋅na2⋅n (1≤ai≤1091≤ai≤109), coordinates, written by Pavel in some order.

Output

Print the only integer, the minimal area of the rectangle which could have contained all points from Pavel's records.

Examples
input

Copy
4
4 1 3 2 3 2 1 3
output

Copy
1
input

Copy
3
5 8 5 5 7 5
output

Copy
0
Note

In the first sample stars in Pavel's records can be (1,3)(1,3), (1,3)(1,3), (2,3)(2,3), (2,4)(2,4). In this case, the minimal area of the rectangle, which contains all these points is 11

(rectangle with corners at (1,3)(1,3) and (2,4)(2,4)).

  给出2n个数自由两两组合为n个坐标,找到一个矩形能包含这n个点,求这个矩形的最小面积。

 先对数组排序,然后考虑枚举一下最小和最大的横坐标,观察后发现当a0视作最左的时候,

把an-1视作最右是最优解,且此时纵坐标的差最小就是a2n-1-an,然后依次递推把x2,x3...视作最左x时候的情况,

会发现此时最优解总是(a2n-1-a0)*(ai+n-1-ai)。扫一遍就好了。

 #include<bits/stdc++.h>
using namespace std;
#define LL long long
#define inf 0x3f3f3f3f
#define pb push_back
#define pii pair<int,int>
LL a[*];
int main(){
int n,i,j,k; while(scanf("%d",&n)!=EOF){
int nn=n*;
for(i=;i<nn;++i) scanf("%lld",a+i);
sort(a,a+nn);
LL ans=(a[n-]-a[])*(a[nn-]-a[n]);
for(i=;i<n;++i)
ans=min(ans,(a[nn-]-a[])*(a[i+n-]-a[i]));
cout<<ans<<endl;
} return ;
}

CF-500div2-A/B/C的更多相关文章

  1. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  2. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  3. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  4. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  5. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  6. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

  7. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  8. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

  9. CF #375 (Div. 2) D. bfs

    1.CF #375 (Div. 2)  D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...

  10. CF #374 (Div. 2) D. 贪心,优先队列或set

    1.CF #374 (Div. 2)   D. Maxim and Array 2.总结:按绝对值最小贪心下去即可 3.题意:对n个数进行+x或-x的k次操作,要使操作之后的n个数乘积最小. (1)优 ...

随机推荐

  1. 干货:Java多线程详解(内附源码)

      线程是程序执行的最小单元,多线程是指程序同一时间可以有多个执行单元运行(这个与你的CPU核心有关). 在java中开启一个新线程非常简单,创建一个Thread对象,然后调用它的start方法,一个 ...

  2. MySQL按中文拼音排序

    好多时候,我们希望查询出来的记录能够按照汉语拼音即英文的26个字母排序,但是utf字符集是外国人弄的,不是按照汉语拼音的顺序排列的,因此,我们需要将要排序的字段把编码设定为GBK或者BG2312再进行 ...

  3. Android 实践项目开发二

    在地图开发中项目中,我这周主要完成的任务是和遇到的问题是以下几个方面. 1.在本次的项目中主要是利用百度地图的.jar包实现地图的定位与搜索功能,需要在百度地图开发中心网站取得 密钥,并下载相关.ja ...

  4. 20162311 Hash 补分博客

    20162311 Hash 补分博客 一.任务详情 二.解题过程 除留余数法和拉链法都懂了,也都会做,主要是开放寻址法.课下查了一些资料,也问了老师才彻底理解 引用例子 引用网上的一个例子来理解 参考 ...

  5. TCP客户端【TcpClient】

    一.阻塞模式 1.命名空间 System.Net.Sockets 2.对象声明 TcpClient dpu1TcpClient = null;//dpu1tcp客户端,TcpClient模式 Netw ...

  6. Linux进程间通信--使用信号量【转】

    本文转载自:http://blog.csdn.net/ljianhui/article/details/10243617 这篇文章将讲述别一种进程间通信的机制——信号量.注意请不要把它与之前所说的信号 ...

  7. keepalived主从及双主配置

    高可用有2中方式. 1.Nginx+keepalived 主从配置 这种方案,使用一个vip地址,前端使用2台机器,一台做主,一台做备,但同时只有一台机器工作,另一台备份机器在主机器不出现故障的时候, ...

  8. 【maven】maven打包deploy时候报错:Connect to repo.maven.apache.org:443

    使用maven打包报错如下: [ERROR] Plugin org.springframework.boot:spring-boot-maven-plugin:1.5.4.RELEASE or one ...

  9. The DELETE statement conflicted with the REFERENCE constraint

    Page是主表,主键是pageid:UserGroupPage表中的PageID字段是Page表里的数据. https://www.codeproject.com/Questions/677277/I ...

  10. TeeChart取消3D

    tChart1.Aspect.View3D = false;//此属性默认是true 3d的效果 2d平面的效果 题外话,在使用控件的时候,需要注意: 在TChart控件上增加Series,   se ...