Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- #define max(x,y) ((x) >= (y)) ? (x) : (y)
- int main() {
- int n;
- int *last = calloc(101, sizeof(int));
- FILE *input = fopen("input.txt", "r");
- fscanf(input, "%d", &n);
- int maxDifference = 0;
- for(int min = 1; min <= n; ++min) {
- int route;
- fscanf(input, "%d", &route);
- if(last[route] != 0) {
- int difference = min - last[route];
- maxDifference = max(maxDifference, difference);
- }
- last[route] = min;
- }
- free(last);
- fclose(input);
- FILE *output = fopen("output.txt", "w");
- fprintf(output, "%d", maxDifference);
- fclose(output);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement