Loading...
Submission
# When Author Problem Language CPU Memory
20824 2024-06-09 08:51:31 AHAMMED_99 Pocket Money C 40 ms 2356 kb Accepted
Test Cases
# CPU Memory Points
1 1 ms 2288 kb 1 Accepted
2 1 ms 2332 kb 1 Accepted
3 40 ms 2276 kb 1 Accepted
4 32 ms 2312 kb 1 Accepted
5 1 ms 2304 kb 1 Accepted
6 5 ms 2356 kb 1 Accepted
7 4 ms 2224 kb 1 Accepted
8 39 ms 2316 kb 1 Accepted
9 1 ms 2308 kb 1 Accepted
10 1 ms 2240 kb 1 Accepted
Source Code
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define MAX 100000
  5.  
  6. // Comparator function for qsort
  7. int compare(const void *a, const void *b) {
  8. return (*(int*)a - *(int*)b);
  9. }
  10.  
  11. // Function to find the smallest note greater than or equal to x using binary search
  12. int findSmallestNote(int *notes, int size, int x) {
  13. int left = 0, right = size - 1;
  14. int result = -1;
  15.  
  16. while (left <= right) {
  17. int mid = left + (right - left) / 2;
  18. if (notes[mid] >= x) {
  19. result = notes[mid];
  20. right = mid - 1;
  21. } else {
  22. left = mid + 1;
  23. }
  24. }
  25.  
  26. return result;
  27. }
  28.  
  29. int main() {
  30. int T;
  31. scanf("%d", &T);
  32.  
  33. while (T--) {
  34. int N, D;
  35. scanf("%d %d", &N, &D);
  36.  
  37. int notes[MAX];
  38. for (int i = 0; i < N; i++) {
  39. scanf("%d", &notes[i]);
  40. }
  41.  
  42. // Sort the notes array
  43. qsort(notes, N, sizeof(int), compare);
  44.  
  45. int requests[MAX];
  46. for (int i = 0; i < D; i++) {
  47. scanf("%d", &requests[i]);
  48. }
  49.  
  50. // Process each request
  51. for (int i = 0; i < D; i++) {
  52. int request = requests[i];
  53. int result = findSmallestNote(notes, N, request);
  54. printf("%d ", result);
  55. }
  56. printf("\n");
  57. }
  58.  
  59. return 0;
  60. }
  61.