online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <iostream> #include <algorithm> #include <array> #include <cstdio> using namespace std; long long int lengthAchieved(long long int barray[], long long int size, long long int setHeight){ long long int length=0; long long int array[size]; for(int i=0;i<size;i++){ array[i]=barray[i]-setHeight; if(array[i]>=0) length=length+array[i]; } cout<<"Length Achieved="<<length<<endl; return length;; } int main() { long long int trees, reqHeight; scanf("%lld %lld", &trees, &reqHeight); long long int height[trees]; for(int i=0;i<trees;i++) scanf("%lld",&height[i]); sort(height,height+(sizeof (height)/sizeof(height[0]))); long long int lo=0, hi=height[trees-1],mid; while(hi>lo){ mid=lo+(1+hi-lo)/2; cout<< "lo="<<lo<<" mid="<<mid<<" hi="<<hi<<endl; long long int length=lengthAchieved(height,trees,mid); if(length==reqHeight){ printf("%d", mid); return 0; } else if(length<reqHeight) hi=mid-1; else if(length>reqHeight) lo=mid; } printf("%d", lo); return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue