http://pl.spoj.com/problems/FZI_STEF/
Ktoś powie gdzie jest błąd?
// ConsoleApplication5.cpp: Definiuje punkt wejścia dla aplikacji konsolowej.
//
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <cmath>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int *x;
int x2;
int i;
int p1;
int p2;
int i2;
int* m;
int* m2;
int z=1;
int i3;
int i4;
int checktop(int c) {
for (i2 = 0, p1 = 0, p2 = 0; i2 < c; i2++, x++)
p1 += *x;
x = m;
return p1;
}
int checkdown(int c2) {
x = x + (x2 - c2);
for (i2 = 0, p1 = 0, p2 = 0; i2 < c2; i2++, x++)
p1 += *x;
x = m;
return p1;
}
int checkall() {
x = m;
for (i2 = 0, p1 = 0, p2 = 0; i2 < x2; i2++,x++) {
p1 += *x;
}
x = m;
return p1;
}
void cutofftop(int c) {
m = m + c;
x = m;
x2 = x2 - c;
}
void cutoffdown(int c) {
x2 = x2 - c;
}
int sercz() {
z = 0;
int *xc = m;
int *xc2 = m;
x = m;
int y;
y = checkall();
for (i3 = 1; i3 < (x2+1); i3++, xc++) {
//cout << *xc << endl;
if (*xc < 0) {
if (checkdown(x2 - i3) > y)
if (checktop(i3 - 1) > checkdown(x2 - i3)) {
xc2 += x2;
for (i4 = x2; i4 > i3 + 1; i4++, xc2--) {
if (*xc2 < 0) { cutoffdown(abs(i4 - x2) + 1); z = 1; break; }
}
if (z == 0) {
cutoffdown(x2 - i3 + 1);
z = 1;
break;
}
}
else {
//for (i4 = x2; i4 > i3 + 1; i4++, xc2--) {
// if (*xc2 < 0) { cutoffdown(abs(i4 - x2) + 1); z = 1; break; }
//}
//if (z == 0) {
cutofftop(i3);
z = 1;
break;
}
else if (checktop(i3-1) > y) {
xc2 += x2;
for (i4 = x2; i4 > i3 + 1; i4++, xc2--) {
if (*xc2 < 0) { cutoffdown(abs(i4 - x2) + 1); z = 1; break;}
}
if (z == 0) {
cutoffdown(x2 - i3 + 1);
z = 1;
break;
}
}
}
}
x = m;
return 1;
}
int main() {
cin >> x2;
x = new int[x2];
m = x;
m2 = x;
for (i = 0; i < x2; i++, x++) cin.ignore(), cin >> *x;
x = m;
while (z == 1) sercz();
cout << checkall() << endl;
x = m2;
delete[] x;
return 0;
}