Cod sursa(job #801754)

Utilizator misinoonisim necula misino Data 24 octombrie 2012 21:33:22
Problema Ferma2 Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include<fstream>
using namespace std;
ifstream f("ferma2.in");
ofstream g("ferma2.out");
int n,p,k,i,j,ii,jj,maxi,mini,sum,jj1,a[1001][1001],s[1001][1001];
char s1[1<<20];
int nr()
{int nr=0;
while(s1[p]<'0'||s1[p]>'9')
	++p;
while(s1[p]<='9'&&s1[p]>='0')
{
nr=nr*10+s1[p]-'0';++p;
}
return  nr;
}
int main()
{f>>n>>k;f.getline(s1,1000000);
for(i=1;i<=n;++i)
{f.getline(s1,1000000);
p=0;
for(j=1;j<=i;++j)
	a[i][j]=nr();
}
for(i=1;i<=n;++i)
	for(j=1;j<=i;++j)
		s[i][j]=s[i][j-1]+a[i][j],maxi+=a[i][j];
mini=maxi+1;
for(i=n-k;i<=n;++i)
	for(j=n-k;j<=i;++j)
	{sum=0;
	ii=i;
	jj=j;
	for(jj1=1;jj1<=n-k;++jj1)
	{sum+=s[ii][jj]-s[ii][jj-(n-k-jj1+1)];
	--ii;
	--jj;
	}
	if(mini>sum)
		mini=sum;
	}
g<<maxi-mini<<'\n';
return 0;
}