Submission details
Task:Maximum sum
Sender:ind1f
Submission time:2025-09-15 16:30:36 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:19:12: error: no matching function for call to 'max(int&, long long int)'
   19 |     f = max(a[i], a[i] + f);
      |         ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from input/code.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
input/code.cpp:19:12: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   19 |     f = max(a[i], a[i] + f);
      |         ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,...

Code

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;

int n;
int a[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  long long ans = a[1], f = a[1];
  for (int i = 2; i <= n; i++) {
    f = max(a[i], a[i] + f);
    ans = max(ans, f);
  }
  cout << ans << '\n';
  return 0;
}