Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <malloc.h>
  3.  
  4. #define max(x,y) ((x) >= (y)) ? (x) : (y)
  5.  
  6. int main() {
  7. int n;
  8. int *last = calloc(101, sizeof(int));
  9. FILE *input = fopen("input.txt", "r");
  10. fscanf(input, "%d", &n);
  11. int maxDifference = 0;
  12. for(int min = 1; min <= n; ++min) {
  13. int route;
  14. fscanf(input, "%d", &route);
  15. if(last[route] != 0) {
  16. int difference = min - last[route];
  17. maxDifference = max(maxDifference, difference);
  18. }
  19. last[route] = min;
  20. }
  21. free(last);
  22. fclose(input);
  23. FILE *output = fopen("output.txt", "w");
  24. fprintf(output, "%d", maxDifference);
  25. fclose(output);
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement