| Task: | Maximum sum |
| Sender: | aalto26cm_014 |
| Submission time: | 2026-09-14 17:48:16 +0300 |
| Language: | C++ (C++20) |
| Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int main()':
input/code.cpp:10:9: error: return-statement with no value, in function returning 'int' [-fpermissive]
10 | return;
| ^~~~~~Code
#include "iostream"
#include "algorithm"
int main() {
int n;
std::cin >> n;
if (n <= 0) {
std::cout << 0 << std::endl;
return;
}
int values[n];
for (int i = 0; i < n; i++) {
std::cin >> values[i];
}
int sums[n+1];
for (int i = 0; i <= n; i++) {
sums[i] = 0;
}
int max = values[0];
for (int i = 1; i <= n; i++) {
sums[i] = std::max(values[i - 1], values[i - 1] + sums[i - 1]);
if (sums[i] > max) max = sums[i];
}
std::cout << max << std::endl;
}