Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
RecursiveDivide
//Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x86 #include <iostream> #include <climits> int maxSubArray(int arr[],int l,int h); int maxSumArray(int arr[],int l,int m,int h); int max(int a,int b,int c); int max(int a,int b); int main() { std::cout << "Hello, world!\n"; int arr[]={7,8,9,5,2,11,3}; int n = sizeof(arr)/sizeof(arr[0]); int value = maxSubArray(arr,0,n-1); std::cout<<value; } int maxSubArray(int arr[],int l,int h) { if(l<=h){ return arr[l]; } int m = (l+h)/2; return max(maxSubArray(arr,l,m),maxSubArray(arr,m+1,h),maxSumArray(arr,l,m,h)); } int maxSumArray(int arr[],int l,int m,int h){ std::cout<<l<<m<<h<<std::endl; int sum =0; int left_sum=INT_MIN; for(int i=m;i>=l;i++){ sum = sum + arr[i]; if(sum > left_sum){ left_sum = sum; } } sum =0; int right_sum = INT_MIN; for(int i=m+1;i<=h;i++){ sum = sum + arr[i]; if(sum > right_sum){ right_sum = sum; } } return left_sum + right_sum; } int max(int a,int b,int c){ return max(max(a,b),c); } int max(int a,int b){ return (a>b)?a:b; }
run
|
edit
|
history
|
help
0
namespace name resolution
#21
fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
throwing an exception containing a unique_ptr is dangerous
Competitive - Algorithm for max number of superior characters
Wide string to lowercase
c++ pure apstraction
Full System Specifications version 2
VS struct name enumerate
find vs at