CSES - Aalto Competitive Programming 2024 - wk3 - Mon - Results
Submission details
Task:Maximum sum
Sender:Rasse
Submission time:2024-09-16 17:10:30 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i = 1; i < vals.size(); i++)
      |                     ~~^~~~~~~~~~~~~
input/code.cpp:21:24: error: no matching function for call to 'max(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, long long int)'
   21 |         maxEnding = max(vals[i], maxEnding + vals[i]);
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
                 from /usr/include/c++/11/ios:40,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from input/code.cpp:2:
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _...

Code

// Online C++ compiler to run C++ program online
#include <iostream>
#include <vector>

using namespace std;

int main() {
    
    int n; // Length of array
    cin >> n;
    
    vector<int> vals(n);
    for (int i = 0; i < n; i++)
    {
        cin >> vals[i];
    }
    long long int res = vals[0];
    long long int maxEnding = vals[0];
    for (int i = 1; i < vals.size(); i++)
    {
        maxEnding = max(vals[i], maxEnding + vals[i]);
        res = max(maxEnding, res);
    }
    
    cout << res;
    
    
    

    return 0;
}