# code forces round 331 div2

262人阅读 评论(0)

A. Wilbur and Swimming Pool
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.

Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 4) — the number of vertices that were not erased by Wilbur's friend.

Each of the following n lines contains two integers xi and yi ( - 1000 ≤ xi, yi ≤ 1000) —the coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.

It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.

Output

Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print  - 1

Sample test(s)
input
2
0 0
1 1

output
1

input
1
1 1

output
-1

Note

In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.

In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area.

/*************************************************************************
> File Name: A.cpp
> Author: kanberra
> Mail: kanberra354562007@gmail.com
> Created Time: 三 11/18 20:50:57 2015
************************************************************************/
#include <bits/stdc++.h>
using namespace std;
pair<int,int> p[10005];
int main(){
int n;
while (scanf("%d",&n)==1){
for (int i=0;i<n;i++)
scanf("%d%d",&p[i].first,&p[i].second);
if (n==1){
puts("-1");
continue;
}
sort(p,p+n);
if (n==4){
cout<<(p[3].second-p[2].second)*(p[3].first-p[0].first);
}else if (n==3){
int len=p[2].first-p[0].first;
int wid=0;
for (int i=0;i<3;i++){
for (int j=i+1;j<3;j++){
wid=max(wid,abs(p[j].second-p[i].second));
}
}
cout<<wid*len<<endl;
}else {
if (p[0].second==p[1].second||p[0].first==p[1].first){
puts("-1");
continue;
}
else cout<<abs(p[0].second-p[1].second)*abs(p[0].first-p[1].first)<<endl;
}
}
return 0;
}

B. Wilbur and Array
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Wilbur the pig is tinkering with arrays again. He has the array a1, a2, ..., an initially consisting of n zeros. At one step, he can choose any index i and either add 1 to all elements ai, ai + 1, ... , an or subtract 1 from all elements ai, ai + 1, ..., an. His goal is to end up with the array b1, b2, ..., bn

Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the array ai. Initially ai = 0 for every position i, so this array is not given in the input.

The second line of the input contains n integers b1, b2, ..., bn ( - 109 ≤ bi ≤ 109).

Output

Print the minimum number of steps that Wilbur needs to make in order to achieve ai = bi for all i.

Sample test(s)
input
5
1 2 3 4 5

output
5
input
4
1 2 2 1

output
3
Note

In the first sample, Wilbur may successively choose indices 1234, and 5, and add 1 to corresponding suffixes.

In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.

/*************************************************************************
> File Name: B.cpp
> Author: kanberra
> Mail: kanberra354562007@gmail.com
> Created Time: 三 11/18 21:08:00 2015
************************************************************************/
#include <bits/stdc++.h>
using namespace std;
int a[1000005];
int main(){
int n;
while (scanf("%d",&n)==1){
for (int i=0;i<n;i++){
scanf("%d",&a[i]);
}
int cnt=0;
long long sum=0;
for (int i=0;i<n;i++){
if (a[i]>cnt){
sum+=a[i]-cnt;
cnt+=a[i]-cnt;
}else if (a[i]<cnt){
sum+=cnt-a[i];
cnt-=(cnt-a[i]);
}
}
cout<<sum<<endl;
}
return 0;
}

1
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：6176次
• 积分：266
• 等级：
• 排名：千里之外
• 原创：21篇
• 转载：0篇
• 译文：0篇
• 评论：0条
阅读排行
评论排行