Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Read inputs from stdin. Write outputs to stdout.
- #include <stdlib.h>
- #include <stdio.h>
- typedef struct
- {
- int x;
- int y;
- } Point;
- static int n;
- static Point *p;
- int compare_x(const void *a, const void *b)
- {
- return (((Point*)a)->x - ((Point*)b)->x);
- }
- int compare_y(const void *a, const void *b)
- {
- return (((Point*)a)->y - ((Point*)b)->y);
- }
- void init()
- {
- int i;
- scanf("%d\n", &n);
- p = malloc(n * sizeof(Point));
- for (i=0; i<n; i++)
- {
- scanf("%d %d\n", &p[i].x, &p[i].y);
- }
- }
- long long result()
- {
- long long length;
- int med;
- int i;
- qsort(p, n, sizeof(Point), compare_x);
- length = p[n-1].x - p[0].x;
- qsort(p, n, sizeof(Point), compare_y);
- med = p[n/2].y;
- for (i=0; i<n; i++)
- {
- int l;
- l = p[i].y - med;
- length += (l > 0 ? l : -l);
- }
- return length;
- }
- int main()
- {
- init();
- printf("%ld", result());
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement