Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdint.h>
- #include <stdlib.h>
- typedef struct
- {
- int first_;
- int second_;
- int third_;
- } triple;
- int cmp(const void* a, const void* b)
- {
- const triple f = *(triple*)a;
- const triple s = *(triple*)b;
- if (f.third_ < s.third_) return -1;
- if (f.third_ > s.third_) return 1;
- return 0;
- }
- int main()
- {
- FILE* in = fopen("vase.in", "r");
- FILE* out = fopen("vase.out", "w");
- int n = 0, t = 0;
- fscanf(in, "%d%d", &n, &t);
- triple* arr = malloc(n * sizeof(triple));
- int64_t sum = 0, minus = 0;
- for (triple* p = arr; p != arr + n; p++)
- {
- int f = 0, s = 0;
- fscanf(in, "%d%d", &f, &s);
- p->first_ = f;
- p->second_ = !f ? 0 : s;
- p->third_ = !s || !f ? t + 2 : f / s + (!(f % s) ? 0 : 1);
- sum += f;
- minus += p->second_;
- }
- qsort(arr, n, sizeof(triple), cmp);
- int move = 0;
- fprintf(out, "%lld\n", sum);
- for (int i = 1; i <= t; i++)
- {
- if (sum)
- {
- while (move < n && i == arr[move].third_)
- {
- sum -= !(arr[move].first_ % arr[move].second_) ? arr[move].second_ : arr[move].first_ % arr[move].second_;
- minus -= arr[move].second_;
- move++;
- }
- sum -= minus;
- }
- fprintf(out, "%lld\n", sum);
- }
- free(arr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement