Cod sursa(job #1632314)

Utilizator GeanaVladGeana Vlad GeanaVlad Data 6 martie 2016 00:24:53
Problema Orase Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<stdio.h>
using namespace std;
struct coord
{
    int x,y;
};
coord v[50001];
int dist(int i,int j)
{
    return v[i].y+v[j].y+v[j].x-v[i].x;
}
int diferenta(int i,int j)
{
    return v[j].x-v[i].x+v[j].y-v[i].y;
}
void qsort(int ls,int ld)
{
    int i,j,x;
    i=ls;j=ld;
    x=v[(i+j)/2].x;
    while(i<=j)
    {
        while(i<ld && v[i].x<x) i++;
        while(j>ls && v[j].x>x) j--;
        if(i<=j)
        {
            swap(v[i],v[j]);
            i++;
            j--;
        }
        if(j>ls) qsort(ls,j);
        if(i<ld) qsort(i,ld);
    }
}
int x,y,n,m,i,j,mx,d[50001];
int main()
{
   freopen("orase.in","r",stdin);
   freopen("orase.out","w",stdout);
   scanf("%d%d", &m, &n);
   for(i=1;i<=n;i++)
       scanf("%d%d", &v[i].x, &v[i].y);
   qsort(1,n);
   for(i=2;i<=n;i++)
        {
            d[i]=max(dist(i-1,i),d[i-1]+diferenta(i-1,i));
            mx=max(mx,d[i]);
        }
   printf("%d", mx);
}