Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. int maxval(int A[],int n,int maximum)
  6. {
  7.  
  8. for(int i=1;i<=n;i++)
  9. {
  10. if(A[i-1]>A[i])
  11. {
  12. maximum = A[i-1];
  13. }
  14. else
  15. maximum = A[i];
  16. }
  17. return maximum;
  18. }
  19. int main()
  20. {
  21. int n,w;
  22. int wood;
  23. int maximum;
  24.  
  25. cout<<"enter the number of trees and required wood:";
  26. cin>>n>>w;
  27. int A[n];
  28. cout<<endl<<"enter the size of the trees:";
  29. for(int i=0;i<n;i++)
  30. {
  31. cin>>A[i];
  32. }
  33. int t= maxval(A,n,maximum);
  34. for(int j=0;j<n;j++)
  35. {
  36. if( A[j] == t )
  37. {
  38. A[j]=A[j]-1;
  39. wood++;
  40. t--;
  41. }
  42. if(wood>=w)
  43. {
  44. cout<<endl<<"cut required:"<<j;
  45. break;
  46. }
  47.  
  48. }
  49.  
  50.  
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement