Advertisement
Mr_kindle

treasurehunt.c

Oct 27th, 2022 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.54 KB | None | 0 0
  1. /*You are participating in a Treasure hunt contest which has 11 hidden items
  2. labeled 1 through 11 (item 1, item 2….. item 11) to be found. The first eight hidden items:
  3. item 1,2…item 8 are worthy of gaining points, while the last three hidden items- item 9, item
  4. 10 and item 11 are not worthy, which means that if we find any of these 3 hidden items does
  5. not affect your total gaining points count.
  6. Your total points are the sum of your best points you gained for all worthy hidden items you
  7. found based on the time taken. That is, for each worthy item, you look at all the gained points
  8. based on the time taken and consider maximum of these points (or 0 if you didn't find a
  9. particular hidden item); the total points is the sum of the maximum gained points.
  10. You know the results of all your gained points. Calculate your total acquired points.
  11. Input
  12.  The first line of the input contains a single integer 'A' denoting the number of test cases.
  13.  The first line of each test case contains a single integer 'T' denoting the number of hidden
  14. items you found.
  15.  'T' lines follow. For each i (1 ≤ i ≤ T), the i-th of these lines contains two space-separated
  16. integers pi and Si, denoting that your i-th found item was on item pi and it received points Si
  17. Output
  18.  For each test case, print a single line containing one integer ― your total acquired points*/
  19.  
  20. /*input
  21. 2
  22. 4
  23. 2 51
  24. 9 103
  25. 8 0
  26. 2 15
  27. 1
  28. 11 1
  29. output
  30. 51
  31. 0
  32. youtube: https://youtu.be/M1a9UAKAYO0
  33.  
  34. */
  35.  
  36. #include<stdio.h>
  37. #include<malloc.h>
  38.  
  39. int main()
  40. {
  41.     int test_case, *item,*points,p[8],i,k,n,sum;
  42.     // array p[] is used in switch to find maximum points of a item
  43.     // n is the number of item found and sum is the total acquired points
  44.  
  45.     printf("enter the number of test cases :");
  46.     scanf("%d", &test_case);
  47.    
  48.    
  49.     while(test_case)
  50.     {
  51.         test_case--;
  52.         printf("\n\n enter the number of items found :");
  53.         scanf("%d", &n);
  54.         item = calloc(n,sizeof(int));
  55.         points = calloc(n,sizeof(int));
  56.         printf("now enter the working status of waiters for everyday where 1 denotes working and 0 denotes leave:");
  57.         for(i=0;i<n;i++)
  58.         {
  59.             printf("\n enter the item no. and points  :");
  60.             scanf("%d %d",&item[i],&points[i]);
  61.         }
  62.         for(i=0;i<8;i++)
  63.         {
  64.             p[i]=0;
  65.         }
  66.         for(i=0;i<n;i++)
  67.         {
  68.             if(item[i]>8)//unworthypoints
  69.             continue;
  70.             k=item[i]-1;//p[k] represent k+1 item
  71.             p[k]=p[k]>points[i]?p[k]:points[i];
  72.         }
  73.         sum = p[0]+p[1]+p[2]+p[3]+p[4]+p[5]+p[6]+p[7];
  74.         printf(" total acquired points are : %d", sum);
  75.         free(item);
  76.         free(points);
  77.     }
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement