Friday, 10 April 2015

                           !!  FIRST NO WHICH  CANT BE FORMED !!

THERE  IS A SET OF NUMBERS  U NEED TO FIND FIRST NO WHICH CANT BE FORMEND
BY USING THAT NUMBER ..

EX
LET 3 AND 5 IS MISSING FROM INFINITE SET OF INTEGER ..

THAN
1 CAN BE FORMED
2 CAN BE FORMED
3 CAN BE FORMED(1+2) SINCE 1 AND 2 IS PRESENT
4 CAN BE FORMED
5 CAN BE FORMED
6 CAN BE FORMED (4+2)
7 CAN BE FORMED(1+2+4)
8 CANT FORMED


#################################EDITORIAL#####################













#################################CODE##################################

  1. #include<iostream>
  2. using namespace std;
  3. #include<algorithm>
  4. int main()
  5. {
  6. int t;
  7. cin>>t;
  8. while(t--)
  9. {
  10. long long int m,n;
  11. cin>>n>>m; // WHARE M IS MAXIMUM VALUED NO IN SET AND M IS NO OF NUMBERS MISSING
  12. long long int arr[m];
  13. for(int i=0;i<m;i++)// READING MISSING NOS
  14. cin>>arr[i];
  15. sort(arr,arr+m);
  16. int sum=0,f=0;
  17. for(int i=0;i<m;i++)
  18. {
  19. sum+=arr[i];
  20. if(arr[i]*(arr[i]+1)/2-sum<arr[i])
  21. {
  22. if(arr[i]%2==1) cout<<"Chef\n";
  23. else
  24. cout<<"Mom\n";
  25. // cout<<arr[i]<<endl;
  26. f=1;
  27. break;
  28. }
  29. }
  30. if(f==0)
  31. {
  32. if((n*(n+1)/2-sum)%2==0) cout<<"Chef\n";
  33. else
  34. cout<<"Mom\n";
  35. }
  36. }
  37. return 0;
  38. }

No comments:

Post a Comment