Friday, 10 April 2015

                               ONE KINGDOME!!

N one dimensional kingdoms are represented as intervals of the form [ai , bi] on the real line.
A kingdom of the form [L, R] can be destroyed completely by placing a bomb at a point x on the real line if L
≤ x ≤ R
.
Your task is to determine minimum number of bombs required to destroy all the one dimensional kingdoms.

OR
THERE ARE MANY HORIZONTAL LINES  PARALALL TO X AXIX   . FIND MINIMUM NO OF VERTICAL LINE NEEDED TO CUT ALL   LINES ....

#########################################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;
  12. long long int arr[m];
  13. for(int i=0;i<m;i++)
  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