Created
May 4, 2016 01:39
-
-
Save olegon/5a24dbc561db48a6f114ffb4bb5ba235 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define SIZE 1000000 | |
typedef struct item { | |
int entrada, | |
saida; | |
} ITEM; | |
int diferenca(const void *a, const void *b); | |
int main (void) { | |
ITEM *agenda; | |
int casos, | |
i, | |
ultimaSaida, | |
presencas; | |
agenda = malloc(sizeof(ITEM) * SIZE); | |
while (scanf("%d", &casos) != EOF) { | |
for (i = 0; i < casos; i++) { | |
scanf("%d %d\n", &agenda[i].entrada, &agenda[i].saida); | |
} | |
qsort(agenda, casos, sizeof(ITEM), diferenca); | |
ultimaSaida = agenda[0].saida; | |
presencas = 1; | |
for (i = 1; i < casos; i++) { | |
if (agenda[i].entrada >= ultimaSaida) { | |
presencas++; | |
ultimaSaida = agenda[i].saida; | |
} | |
} | |
printf("%d\n", presencas); | |
} | |
return 0; | |
} | |
int diferenca(const void *a, const void *b) { | |
const ITEM *x = a; | |
const ITEM *y = b; | |
if (x->entrada == y->entrada) { | |
return x->saida - y->saida; | |
} | |
else { | |
return x->entrada - y->entrada; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment