fork download
  1. typedef long long ll;
  2. ll solve(int *arr, int len){
  3. if (len == 2){
  4. return (arr[0]+arr[1]);
  5. }
  6. else if (len == 3){
  7. return max(max(arr[0]+arr[1], arr[1]+arr[2]), 2*(arr[0]+arr[2]));
  8. }
  9. else {
  10. int half = len >> 1;
  11. ll left_sol = solve(arr,half);
  12. ll right_sol = solve(arr+half, half + (len%2));
  13. ll crossing_sol = -1;
  14. int indices_grow[half];
  15. int indices_decay[half+(len%2)];
  16. int maxi = -1;
  17. int count1 = -1;
  18. ll temp = 0;
  19. for (int i = 0; i < half; ++i){
  20. if (arr[i] > maxi){
  21. indices_grow[++count1] = i;
  22. maxi = arr[i];
  23. }
  24. }
  25. int count2 = -1;
  26. maxi = -1;
  27. for (int j = len-1; j >= half; --j){
  28. if (arr[j] > maxi){
  29. indices_decay[++count2] = j;
  30. maxi = arr[j];
  31. }
  32. }
  33. for (int i =0; i <= count1; ++i){
  34. for (int j = 0; j <= count2; ++j){
  35. temp = (arr[indices_grow[i]] + arr[indices_decay[j]]);
  36. temp =temp*(indices_decay[j] - indices_grow[i]);
  37. if (crossing_sol < temp){
  38. crossing_sol = temp;
  39. }
  40. }
  41. }
  42.  
  43. return max(max(left_sol, right_sol), crossing_sol);
  44.  
  45. }
  46. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘ll solve(int*, int)’:
prog.cpp:7:20: error: ‘max’ was not declared in this scope
         return max(max(arr[0]+arr[1], arr[1]+arr[2]), 2*(arr[0]+arr[2]));
                    ^~~
prog.cpp:7:16: error: ‘max’ was not declared in this scope
         return max(max(arr[0]+arr[1], arr[1]+arr[2]), 2*(arr[0]+arr[2]));
                ^~~
prog.cpp:43:20: error: ‘max’ was not declared in this scope
         return max(max(left_sol, right_sol), crossing_sol);
                    ^~~
prog.cpp:43:20: note: suggested alternative: ‘maxi’
         return max(max(left_sol, right_sol), crossing_sol);
                    ^~~
                    maxi
prog.cpp:43:16: error: ‘max’ was not declared in this scope
         return max(max(left_sol, right_sol), crossing_sol);
                ^~~
prog.cpp:43:16: note: suggested alternative: ‘maxi’
         return max(max(left_sol, right_sol), crossing_sol);
                ^~~
                maxi
stdout
Standard output is empty