| Task: | Maximum sum |
| Sender: | aalto26cm_030 |
| Submission time: | 2026-09-14 16:43:00 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.00 s | details |
| #2 | WRONG ANSWER | 0.00 s | details |
| #3 | WRONG ANSWER | 0.00 s | details |
| #4 | WRONG ANSWER | 0.00 s | details |
| #5 | WRONG ANSWER | 0.00 s | details |
| #6 | WRONG ANSWER | 0.06 s | details |
| #7 | WRONG ANSWER | 0.07 s | details |
| #8 | WRONG ANSWER | 0.13 s | details |
| #9 | WRONG ANSWER | 0.13 s | details |
| #10 | WRONG ANSWER | 0.13 s | details |
| #11 | WRONG ANSWER | 0.00 s | details |
| #12 | WRONG ANSWER | 0.00 s | details |
| #13 | WRONG ANSWER | 0.00 s | details |
| #14 | WRONG ANSWER | 0.00 s | details |
| #15 | WRONG ANSWER | 0.00 s | details |
Compiler report
input/code.cpp: In function 'void continnousSum()':
input/code.cpp:396:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
396 | for (int idx = 1; idx < arrMax.size(); idx++){
| ~~~~^~~~~~~~~~~~~~~Code
#include <iostream>
#include <vector>
#include <functional>
void printNewLine(){std::cout << "\n";}
template<typename T, typename... Ts>
std::tuple<Ts...> tail(std::tuple<T,Ts...> as){
return std::apply([](T &a, Ts... b){return std::make_tuple(b...);},as);
}
template<typename T>
void print(T a){std::cout << a;}
template<typename T, typename Ts>
void print(std::tuple<T,Ts> a){
print(std::get<0>(a));
print(" ");
print(std::get<1>(a));
}
template<typename T, typename... Ts>
void print(std::tuple<T,Ts...> a){
print(std::get<0>(a));
print(" ");
print(tail(a));
}
template<typename T>
void println(T a){print(a);printNewLine();}
template<typename T>
void printVec(std::vector<T> arr, int width = -1){
if (width == -1) width = arr.size();
for (int i = 0; i < (int)arr.size(); i++){
if ((i%width) == width-1){
print(" ");
println(arr[i]);
}else if ((i%width) == 0){
print(arr[i]);
}else {
print(" ");
print(arr[i]);
}
}
}
std::tuple<int> readInt1(){
int a;
std::cin >> a;
return {a};
}
std::tuple<int,int> readInt2(){
int a, b;
std::cin >> a >> b;
return {a,b};
}
std::tuple<int,int,int> readInt3(){
int a, b, c;
std::cin >> a >> b >> c;
return {a,b,c};
}
std::vector<int> readVecInt(int n){
std::vector<int> arr(n);
for (int i = 0; i < n; i++){
int a;
std::cin >> a;
arr[i] = a;
}
return arr;
}
std::vector<std::tuple<int,int>> readVecTup2(int n){
std::vector<std::tuple<int,int>> arr(n);
for (int i = 0; i < n; i++){
int a, b;
std::cin >> a;
std::cin >> b;
arr[i] = {a,b};
}
return arr;
}
std::vector<std::tuple<int,int,int>> readVecTup3(int n){
std::vector<std::tuple<int,int,int>> arr(n);
for (int i = 0; i < n; i++){
int a, b, c;
std::cin >> a;
std::cin >> b;
std::cin >> c;
arr[i] = {a,b,c};
}
return arr;
}
template<typename T>
auto getTupleSort(){
auto tupleSort = [](const std::tuple<T,T> &a, const std::tuple<T,T> &b){
auto [ax, ay] = a;
auto [bx, by] = b;
return ay < by; };
return tupleSort;
}
template<typename T>
void sortBy(std::vector<T> &arr){
std::sort(arr.begin(),arr.end(),[](const T &a, const T &b){ return a < b; });
}
template<typename T>
T binarySearch(T min, T max, std::function<bool(T)> leq){
if (min == max) return max;
T guess = (min+max)/2;
if (leq(guess)){
return binarySearch(min,guess,leq);
}else{
return binarySearch(guess+1,max,leq);
}
}
template<typename T>
T binarySearchDecending(T min, T max, std::function<bool(T)> leq){
std::function<bool(T)> gt = [leq](T x){
return !leq(x);
};
return binarySearch(min,max+1, gt)-1;
}
void carManufacturing(){
auto [n, t] = readInt2();
//auto [n, m, k] = readInt3();
auto arr = readVecInt(n);
double s = 0;
for (int x: arr){
s += 1.0/x;
}
std::function<bool(long long)> leq = [&arr,t](long long time){
long long s = 0;
for (int x : arr){
s += time/x;
}
return t <= s;
};
println(binarySearch((long long)0,(long long)(t/s*(long long)n),leq));
}
template<typename T>
double avg(std::vector<T> &arr){
double mult = 1.0/arr.size();
double s = 0;
for (T x : arr){
s += mult*(double)x;
}
return s;
}
template<typename T>
T sum(std::vector<T> &arr){
T s = 0;
for (T x : arr){
s += x;
}
return s;
}
void bottle(){
auto [n] = readInt1();
//auto [n, t] = readInt2();
//auto [n, m, k] = readInt3();
auto arr = readVecInt(n);
double s = avg(arr);
std::function<bool(long long)> leq = [&arr](long long t){
long long s = 0;
for (long long x : arr){
if (x-t > 0){
s += (x-t)/2;
}else{
s += (x-t);
}
}
return 0 <= s;
};
println(binarySearchDecending((long long)0,(long long)(s),leq));
}
#include <set>
#include <algorithm>
void movie(){
auto [n] = readInt1();
auto arr = readVecInt(2*n);
int* s = &arr[0];
std::sort((long*)(s),(long*)(s)+n);
int time = 0;
int num = 0;
for (int i = 0; i < n; i++){
if (time <= arr[2*i]){
time = arr[2*i+1];
num += 1;
}
}
println(num);
}
/*
for (int i = 0; i < n; i++){
int temp = arr[2*i+1];
arr[2*i+1] = arr[2*i];
arr[2*i] = temp;
}
*/
void cow(){
auto [n] = readInt1();
auto dum = readVecInt(n);
print(1);
for (int i = 1; i < 30; i++){
print(" ");
if ((1<<i) <= 1000*1000*1000){
print(1<<i);
} else{
print(0);
}
}
}
template<typename T>
std::vector<T> cloneVec(std::vector<T> a){
return a;
}
void castle(){
auto [n] = readInt1();
auto arr = readVecTup2(n);
std::vector<std::tuple<int,int>> arr2 = cloneVec(arr);
for (int i = 0; i < n; i++){
auto [u,m] = arr[i];
arr2[i] = {-(u+m),i};
}
sortBy(arr2);
int us = 0;
int ms = 0;
printVec(arr2);
for (int i = 0; i < n; i++){
auto [s,idx] = arr2[i];
auto [u,m] = arr[idx];
if (i%2 == 0){
us += u;
} else {
ms += m;
}
}
println(us-ms);
}
template<typename T>
void extendedFibonachi(std::vector<T> &initial, int nlast, T upto, T mod ){
for (int i = nlast; i <= upto; i++){
initial[i] = 0;
for (int n = 1; n <= nlast && n <= i; n++){
initial[i] += initial[i-n];
initial[i] %=mod;
}
}
}
void dice(){
auto [n] = readInt1();
std::vector<long long> arr(std::max(7,n+1));
arr[0] = 1;
for (int i = 0; i < 6; i++){
arr[i+1] = 1<<i;
}
extendedFibonachi(arr,6,(long long)n,(long long)1000*1000*1000+7);
println(arr[n]);
}
template<typename T>
std::vector<T> padding(std::vector<T> &initial, T num, int start, int end){
std::vector<T> arr(start+initial.size()+end);
for (int i = 0; i < start; i++){
arr[i] = num;
}
for (int i = 0; i < (int)initial.size(); i++){
arr[start+i] = initial[i];
}
for (int i = 0; i < end; i++){
arr[start+initial.size()+i] = num;
}
return arr;
}
template<typename T>
int findMax(int start, int end, std::function<T(int)> &maxHeuristic){
T initialGuess = maxHeuristic(start);
int index = start;
for (int i = start; i <= end; i++){
if (initialGuess < maxHeuristic(i)){
initialGuess = maxHeuristic(i);
index = i;
}
}
return index;
}
template<typename T>
void operateOnMax(int start, int end, std::function<T(int)> &maxHeuristic, std::function<void(int)> &found){
found(findMax(start,end,maxHeuristic));
}
#include <stack>
template<typename T>
void stackOperate(T init,std::function<std::vector<T>(T)> operate){
std::stack<T> stack;
stack.push(init);
while (!stack.empty()){
T next = stack.top();
stack.pop();
std::vector<T> nextSteps = operate(next);
for (T a : nextSteps){
stack.push(a);
}
}
}
template<typename T>
void recursiveVectorSplit(int start, int end, int distl, int distr, std::function<T(int)> &maxHeuristic, std::function<void(int)> &found){
if (start == end){
return found(start);
}else if (end < start){
return;
}
std::tuple<int,int> range = {start,end};
std::function<std::vector<std::tuple<int,int>>(std::tuple<int,int>)> splitter = [distl, distr,&maxHeuristic,&found](std::tuple<int,int> range){
auto [start,end] = range;
int idx = findMax(start, end, maxHeuristic);
found(idx);
std::vector<std::tuple<int,int>> next;
if (idx+distl+1 <= end){
next.push_back({idx+distl+1,end});
}
if (start <= idx-distr-1){
next.push_back({start, idx-distr-1});
}
return next;
};
stackOperate(range,splitter);
}
void cardGame(){
auto [n] = readInt1();
auto arr = readVecInt(n);
arr[0] = 0;
arr[arr.size()-1] = 0;
//printVec(arr);
arr = padding(arr,0,1,1);
//printVec(arr);
std::function<int(int)> heuristic = [&arr](int idx){
return arr[idx]-arr[idx-1]-arr[idx-2]-arr[idx+1]-arr[idx+2];
};
long long sum = 0;
std::function<void(int)> operate = [&arr, &sum](int idx){
arr[idx-2] = 0;
arr[idx-1] = 0;
sum += arr[idx];
arr[idx+1] = 0;
arr[idx+2] = 0;
//printVec(arr);
};
//printVec(arr);
//println(arr[arr.size()-1-2]);
recursiveVectorSplit(2,(int)arr.size()-1-2,2,2,heuristic,operate);
println(sum);
}
void mariocart(){
auto [n,m,k] = readInt3();
auto arr = readVecInt(m);
std::set<int> c;
for (int a : arr){ c.emplace(a);}
int position = 0;
for (int i = 1; i <=k; i++){
if (c.find(position) != c.end()){
position += 2;
} else {
position += 1;
}
position %= n;
}
println(position*100);
}
void continnousSum(){
auto [n] = readInt1();
auto arr = readVecInt(n);
auto arrMax = cloneVec(arr);
//std::function<int(int)> maxFunc = [&arrMax](int idx){
for (int idx = 1; idx < arrMax.size(); idx++){
arrMax[idx] = std::max(arrMax[idx-1]+arrMax[idx],arrMax[idx]);
};
int m = 0;
for (int a : arrMax){
m = std::max(a,m);
};
printVec(arrMax);
println(m);
}
int main() {
//carManufacturing();
//bottle();
//movie();
//cow();
//castle();
//dice();
//cardGame();
//mariocart();
continnousSum();
exit(0);
}Test details
Test 1
Verdict: WRONG ANSWER
| input |
|---|
| 10 1 1 1 1 1 1 1 1 1 1 |
| correct output |
|---|
| 10 |
| user output |
|---|
| 1 2 3 4 5 6 7 8 9 10 10 |
Feedback: Output is longer than expected
Test 2
Verdict: WRONG ANSWER
| input |
|---|
| 10 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 |
| correct output |
|---|
| -1 |
| user output |
|---|
| -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 |
Feedback: Output is longer than expected
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| 10 24 7 -27 17 -67 65 -23 58 85 -... |
| correct output |
|---|
| 185 |
| user output |
|---|
| 24 31 4 21 -46 65 42 100 185 1... |
Feedback: Output is longer than expected
Test 4
Verdict: WRONG ANSWER
| input |
|---|
| 10 99 -59 31 83 -79 64 -20 -87 40... |
| correct output |
|---|
| 154 |
| user output |
|---|
| 99 40 71 154 75 139 119 32 72 ... |
Feedback: Output is longer than expected
Test 5
Verdict: WRONG ANSWER
| input |
|---|
| 10 -19 61 60 33 67 19 -8 92 59 -3... |
| correct output |
|---|
| 383 |
| user output |
|---|
| -19 61 121 154 221 240 232 324... |
Feedback: Output is longer than expected
Test 6
Verdict: WRONG ANSWER
| input |
|---|
| 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| 200000 |
| user output |
|---|
| 1 2 3 4 5 6 7 8 9 10 11 12 13 ... |
Feedback: Output is longer than expected
Test 7
Verdict: WRONG ANSWER
| input |
|---|
| 200000 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ... |
| correct output |
|---|
| -1 |
| user output |
|---|
| -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ... |
Feedback: Output is longer than expected
Test 8
Verdict: WRONG ANSWER
| input |
|---|
| 200000 381082742 830199996 -85684827 ... |
| correct output |
|---|
| 231210956017 |
| user output |
|---|
| 381082742 1211282738 112559791... |
Feedback: Output is longer than expected
Test 9
Verdict: WRONG ANSWER
| input |
|---|
| 200000 -935928962 -795492223 75287481... |
| correct output |
|---|
| 184607318819 |
| user output |
|---|
| -935928962 -795492223 75287481... |
Feedback: Output is longer than expected
Test 10
Verdict: WRONG ANSWER
| input |
|---|
| 200000 524408131 613017181 -62281009 ... |
| correct output |
|---|
| 360019999220 |
| user output |
|---|
| 524408131 1137425312 107514430... |
Feedback: Output is longer than expected
Test 11
Verdict: WRONG ANSWER
| input |
|---|
| 1 1 |
| correct output |
|---|
| 1 |
| user output |
|---|
| 1 1 |
Feedback: Output is longer than expected
Test 12
Verdict: WRONG ANSWER
| input |
|---|
| 1 -2 |
| correct output |
|---|
| -2 |
| user output |
|---|
| -2 0 |
Feedback: Output is longer than expected
Test 13
Verdict: WRONG ANSWER
| input |
|---|
| 5 -1 -1 -1 -1 -2 |
| correct output |
|---|
| -1 |
| user output |
|---|
| -1 -1 -1 -1 -2 0 |
Feedback: Output is longer than expected
Test 14
Verdict: WRONG ANSWER
| input |
|---|
| 2 -3 -2 |
| correct output |
|---|
| -2 |
| user output |
|---|
| -3 -2 0 |
Feedback: Output is longer than expected
Test 15
Verdict: WRONG ANSWER
| input |
|---|
| 1 -1000000000 |
| correct output |
|---|
| -1000000000 |
| user output |
|---|
| -1000000000 0 |
Feedback: Output is longer than expected
