Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int maxval(int A[],int n,int maximum)
- {
- for(int i=1;i<=n;i++)
- {
- if(A[i-1]>A[i])
- {
- maximum = A[i-1];
- }
- else
- maximum = A[i];
- }
- return maximum;
- }
- int main()
- {
- int n,w;
- int wood;
- int maximum;
- cout<<"enter the number of trees and required wood:";
- cin>>n>>w;
- int A[n];
- cout<<endl<<"enter the size of the trees:";
- for(int i=0;i<n;i++)
- {
- cin>>A[i];
- }
- int t= maxval(A,n,maximum);
- for(int j=0;j<n;j++)
- {
- if( A[j] == t )
- {
- A[j]=A[j]-1;
- wood++;
- t--;
- }
- if(wood>=w)
- {
- cout<<endl<<"cut required:"<<j;
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement