Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <limits.h>
- #include <stdlib.h>
- #include <math.h>
- int main() {
- FILE *fin = fopen("input.txt", "r");
- FILE *fout = fopen("output.txt", "w");
- int n, m, x, k;
- fscanf(fin, "%d%d%d%d", &n, &m, &x, &k);
- int assump, porch, floor;
- int *house = (int *) calloc(n + 1, sizeof(int));
- for (int i = 1; i < k + 1; i++) {
- fscanf(fin, "%d", &assump);
- int(porch) = (x-1)/(m*assump)+1;
- int(floor) = ((x-(porch-1)*m*assump)-1)/assump+1;
- if ((porch - 1) <= n) {
- if (floor > house[porch])
- house[porch] = floor;
- }
- }
- int sum = 0;
- for (int i = 0; i < n + 1; i++) {
- sum += house[i];
- }
- if (sum==0) fprintf(fout,"%s","-1");
- else fprintf(fout,"%d",sum);
- fclose(fin);
- fclose(fout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement