Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <limits.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5.  
  6. int main() {
  7. FILE *fin = fopen("input.txt", "r");
  8. FILE *fout = fopen("output.txt", "w");
  9.  
  10. int n, m, x, k;
  11. fscanf(fin, "%d%d%d%d", &n, &m, &x, &k);
  12.  
  13. int assump, porch, floor;
  14. int *house = (int *) calloc(n + 1, sizeof(int));
  15. for (int i = 1; i < k + 1; i++) {
  16. fscanf(fin, "%d", &assump);
  17. int(porch) = (x-1)/(m*assump)+1;
  18. int(floor) = ((x-(porch-1)*m*assump)-1)/assump+1;
  19. if ((porch - 1) <= n) {
  20. if (floor > house[porch])
  21. house[porch] = floor;
  22. }
  23. }
  24. int sum = 0;
  25. for (int i = 0; i < n + 1; i++) {
  26. sum += house[i];
  27. }
  28. if (sum==0) fprintf(fout,"%s","-1");
  29. else fprintf(fout,"%d",sum);
  30.  
  31. fclose(fin);
  32. fclose(fout);
  33.  
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement