#include "maklib.h"
#include <algorithm>
#include <iostream>
using namespace std;
void wypisz(int n )
{
int i;
cout<<"************"<<endl;
for( i = 1; i <= n; i++ )
{
cout << ElementAt( i) << " ";
if((( i % 10 ) == 0 ) &&( i > 1 ) ) cout << endl;
}
cout << endl;
}
int main() {
vector<int> x;
int suma=ElementAt(1);
x.push_back(0);
if (Size() < 2){
cout << max(0, ElementAt(1)) << endl;
}else{
for(int i=1;i<Size();i++){
if(ElementAt(i)<0){
if(ElementAt(i)>suma){
suma=ElementAt(i);
}
}else if(ElementAt(i)>suma && suma<0){
suma=ElementAt(i);
}else{
suma+=ElementAt(i);
}
}
}
cout<<suma<<endl;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #include "maklib.h" #include <algorithm> #include <iostream> using namespace std; void wypisz(int n ) { int i; cout<<"************"<<endl; for( i = 1; i <= n; i++ ) { cout << ElementAt( i) << " "; if((( i % 10 ) == 0 ) &&( i > 1 ) ) cout << endl; } cout << endl; } int main() { vector<int> x; int suma=ElementAt(1); x.push_back(0); if (Size() < 2){ cout << max(0, ElementAt(1)) << endl; }else{ for(int i=1;i<Size();i++){ if(ElementAt(i)<0){ if(ElementAt(i)>suma){ suma=ElementAt(i); } }else if(ElementAt(i)>suma && suma<0){ suma=ElementAt(i); }else{ suma+=ElementAt(i); } } } cout<<suma<<endl; return 0; } |
English