ENG  RUS Timus Online Judge Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1146. Maximum Sum

Why does my program not work?
Posted by Teh Ming Han 26 May 2002 20:32
//I received an error: Crash (ACCESS_VIOLATION) from the judge

// USU Problem 1146
// Maximum Sum
// Done by Teh Ming Han

#include <iostream.h>
#include <fstream.h>

int main(){
int x1,y1,x2,y2,n,c,max=0;
int sum, work={0};

ifstream infile("maxsum.in");
infile>>n;
for (x1=1;x1<=n;x1++)
for (y1=1;y1<=n;y1++)
infile.close();

for (x1=1;x1<=n;x1++)
for (y1=1;y1<=n;y1++)
for (x2=1;x2<=x1;x2++)
for (y2=1;y2<=y1;y2++)
work[x1][y1] += sum[x2][y2];

for (x1=1;x1<=n;x1++)
for (y1=1;y1<=n;y1++)
for (x2=x1;x2<=n;x2++)
for (y2=y1;y2<=n;y2++){
c = work[x2][y2] - work[x1-1][y2] - work[x2][y1-1] +
work[x1-1][y1-1];
if (c>max) max=c;
}

ofstream outfile("maxsum.out");
outfile<<max;
outfile.close();
return 0;
}
Re: Why does my program not work?
Posted by Nebula 16 Apr 2004 13:52
N may be as large as 100

lucky~
You'll get TLE.
Posted by Vlad Veselov 16 Apr 2004 16:30
As I see your program is O(N^4) and it's to many operations when N = 100.
Re: You'll get TLE.
Posted by sloboz 16 Apr 2004 20:22
your algo is good, theoretically is N^4 but practically fits in time.
First you must not use files, and second put 200 or 110 or something little larger than 100. You'll get AC (I sent your source with these modifications).
Re: what's wrong
Posted by Ciprian 20 May 2008 13:59
u use files.
try using scanf/cin
printf/cout
Re: Why does my program not work?
Posted by Lakers 18 Nov 2011 22:14
use
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
b[i][j] = b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1] + a[i][j];
}
}