Small Hy's four-tuple

Source: Internet
Author: User

Title Description

Cute little hy found a kind of four-tuple in the accident, we define an ordered set of four numbers for the {a,b,c,d} of the four-tuple ancestor. If there is ai-aj=bi-bj=ci-cj=di-dj for I,j (I<J) of the four-tuple {Ai,bi,ci,di} and {AJ,BJ,CJ,DJ} (I,J), it is a pair of four tuples.

Small Hy is a person with a special hobby, now give n four tuples, he wants to know in all the J-i (I,J) The minimum value and the maximum value of i+j. Smart can you tell him the answer?

Input

The input file name is Four.in

The input file has a n+1 line, the first behavior is a number n, next enter n lines, each line a,b,c,d four integers.

Output

Output file name is Four.out

The output is only one row, including the minimum value of the j-i and the maximum value of i+j, separated by a space, the data is guaranteed to have a solution .

Sample input
7 1 2 3 4 2 3 4 5 1 4 3 3 5 2 3 5 2 4 5 6 1 4 3 3 2 5 4 4
Sample output
1 13
Tips

(1,2,3,4) and (2,3,4,5) or (1,4,3,3) and (2,5,4,4) constitute the minimum value.


(1,4,3,3) and (2,5,4,4), 6+7=13 is the maximum value.


"Input and output Example 2"


10


1 4 3 2


4 4 4 4


2 3 4 5


1 1 1 1


1 2 3 1


3 4 2 1


2 4 5 2


8 9 7 6


0 0 0 0


1 2 3 4


2 14


"Data description"


For 30% of data n<=1000


The data n<=500000,a,b,c,d for 100% is within the range of int.

The problem of the big Uncle Lwq12138
#include <cstdio> #include <iostream> #include <algorithm>using namespace Std;int n,minv,maxv;long    Long x,y,z,t;struct ty{long long a,b,c; int id;}    P[500005];bool cmp (ty X,ty y) {if (X.A!=Y.A) return x.a<y.a;    if (x.b!=y.b) return x.b<y.b;    if (X.C!=Y.C) return x.c<y.c; return x.id<y.id;}    int main () {cin>>n;        for (int i=1;i<=n;i++) {scanf ("%lld%lld%lld%lld", &x,&y,&z,&t);        P[i].a=y-x;        P[i].b=z-y;        P[i].c=t-z;    P[i].id=i;    } sort (p+1,p+n+1,cmp);    X=P[1].A;    y=p[1].b;    Z=P[1].C;    minv=1000000000; for (int i=2;i<=n;i++) if (p[i].a!=x| | p[i].b!=y| |        p[i].c!=z) {x=p[i].a;        y=p[i].b;    Z=P[I].C;        } else {minv=min (minv,p[i].id-p[i-1].id);    Maxv=max (maxv,p[i].id+p[i-1].id);    } cout<<minv<< ' <<maxv<<endl; return 0;}





Small Hy's four-tuple

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.