Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*You are participating in a Treasure hunt contest which has 11 hidden items
- labeled 1 through 11 (item 1, item 2….. item 11) to be found. The first eight hidden items:
- item 1,2…item 8 are worthy of gaining points, while the last three hidden items- item 9, item
- 10 and item 11 are not worthy, which means that if we find any of these 3 hidden items does
- not affect your total gaining points count.
- Your total points are the sum of your best points you gained for all worthy hidden items you
- found based on the time taken. That is, for each worthy item, you look at all the gained points
- based on the time taken and consider maximum of these points (or 0 if you didn't find a
- particular hidden item); the total points is the sum of the maximum gained points.
- You know the results of all your gained points. Calculate your total acquired points.
- Input
- The first line of the input contains a single integer 'A' denoting the number of test cases.
- The first line of each test case contains a single integer 'T' denoting the number of hidden
- items you found.
- 'T' lines follow. For each i (1 ≤ i ≤ T), the i-th of these lines contains two space-separated
- integers pi and Si, denoting that your i-th found item was on item pi and it received points Si
- Output
- For each test case, print a single line containing one integer ― your total acquired points*/
- /*input
- 2
- 4
- 2 51
- 9 103
- 8 0
- 2 15
- 1
- 11 1
- output
- 51
- 0
- youtube: https://youtu.be/M1a9UAKAYO0
- */
- #include<stdio.h>
- #include<malloc.h>
- int main()
- {
- int test_case, *item,*points,p[8],i,k,n,sum;
- // array p[] is used in switch to find maximum points of a item
- // n is the number of item found and sum is the total acquired points
- printf("enter the number of test cases :");
- scanf("%d", &test_case);
- while(test_case)
- {
- test_case--;
- printf("\n\n enter the number of items found :");
- scanf("%d", &n);
- item = calloc(n,sizeof(int));
- points = calloc(n,sizeof(int));
- printf("now enter the working status of waiters for everyday where 1 denotes working and 0 denotes leave:");
- for(i=0;i<n;i++)
- {
- printf("\n enter the item no. and points :");
- scanf("%d %d",&item[i],&points[i]);
- }
- for(i=0;i<8;i++)
- {
- p[i]=0;
- }
- for(i=0;i<n;i++)
- {
- if(item[i]>8)//unworthypoints
- continue;
- k=item[i]-1;//p[k] represent k+1 item
- p[k]=p[k]>points[i]?p[k]:points[i];
- }
- sum = p[0]+p[1]+p[2]+p[3]+p[4]+p[5]+p[6]+p[7];
- printf(" total acquired points are : %d", sum);
- free(item);
- free(points);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement