# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1023385 | 2024-07-14T17:31:46 Z | Shadxwed | Fountain (eJOI20_fountain) | C | 1500 ms | 2200 KB |
#include <stdio.h> #include <stdlib.h> // Function to compare two integers (for qsort) int compare(const void *a, const void *b) { return (*(int *)a - *(int *)b); } int main() { int n, q; // Reading number of elements and queries scanf("%d %d", &n, &q); int *d = malloc(n * sizeof(int)); int *v = malloc(n * sizeof(int)); int *prefixSum = malloc((n + 1) * sizeof(int)); int *indices = malloc(n * sizeof(int)); // Reading values into arrays for (int i = 0; i < n; i++) { scanf("%d %d", &d[i], &v[i]); indices[i] = i; // Initialize indices } // Compute prefix sums prefixSum[0] = 0; for (int i = 1; i <= n; i++) { prefixSum[i] = prefixSum[i - 1] + v[i - 1]; } // Sort indices based on the values in d qsort(indices, n, sizeof(int), compare); int q1, q2; for (int i = 0; i < q; i++) { scanf("%d %d", &q1, &q2); q1--; int prev = -1; int remaining = q2; // Binary search to find the appropriate segment for (int j = q1; j < n; j++) { int idx = indices[j]; if (d[idx] > prev) { remaining -= v[idx]; prev = d[idx]; if (remaining <= 0) { printf("%d\n", idx + 1); break; } } } if (remaining > 0) { printf("0\n"); } } // Free allocated memory free(d); free(v); free(prefixSum); free(indices); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 3 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1532 ms | 2200 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 3 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Execution timed out | 1532 ms | 2200 KB | Time limit exceeded |
9 | Halted | 0 ms | 0 KB | - |