Submission #1348343

#TimeUsernameProblemLanguageResultExecution timeMemory
1348343comgaTramAnhRice Hub (IOI11_ricehub)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> 
#include "ricehub.h"
long long sum[100005];
int a[100005];  
long long getSum(int l, int r) {
  long long ret = sum[r]; 
  ret -= sum[l];
  ret += a[l];
  return ret; 
}
int besthub(int n, int L, int X[], long long B) {
  for (int i = 0; i < n; i++) {
    a[i] = X[i]; 
  }
  sum[0] = a[0];
  for (int i = 1; i < n; i++) {
    sum[i] = sum[i - 1] + a[i]; 
  }  
  int ans = -1; 
  for (int i = 0; i < n; i++) {
    int lo = i;
    int hi = n - 1; 
    int pos = -1;
    while (lo <= hi) {
      int mid = (lo + hi) / 2; 
      int med = (i + mid) / 2; 
      long long sumLeft = (long long) (med - i + 1) * a[med] - getSum(i, med); 
      long long sumRight = getSum(med + 1, mid) - (long long) (mid - med) * a[med];
      if (sumLeft + sumRight <= B) {
        pos = mid; 
        lo = mid + 1; 
      }
      else {
        hi = mid - 1; 
      }
    }
    ans = max(ans, pos - i + 1); 
  }
  return ans; 
}

Compilation message (stderr)

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:37:11: error: 'max' was not declared in this scope
   37 |     ans = max(ans, pos - i + 1);
      |           ^~~
ricehub.cpp:37:11: note: suggested alternatives:
In file included from /usr/include/c++/13/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from ricehub.cpp:1:
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   'std::max'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
In file included from /usr/include/c++/13/algorithm:63:
/usr/include/c++/13/bits/ranges_algo.h:2928:29: note:   'std::ranges::max'
 2928 |   inline constexpr __max_fn max{};
      |                             ^~~