9022022-01-26 14:09:21Babják PéterSivatagcpp11Runtime error 0/401ms1220 KiB
#include <bits/stdc++.h>
#define MAXN 1001
#define int long long
using namespace std;
//12 10
int n,m,k,e;
int t1[MAXN][MAXN];
int t2[MAXN][MAXN];
int t3[MAXN][MAXN];
int t4[MAXN][MAXN];
int g[MAXN][MAXN];
signed main()
{
	cin>>m>>n>>k>>e;

	for(int i=0;i<e;i++)
	{
		int a,b,c,d;
		cin>>b>>a>>d>>c;
		a=(n+1)-a;
		c=(n+1)-c;
		t1[a+1][b]--;
		t1[c][b]++;
		t1[c][d+1]--;
		t1[a+1][d+1]++;
	}
	for(int i=0;i<=n;i++)
	{
		int akt=0;
		for(int j=0;j<=m;j++)
		{
			akt+=t1[i][j];
			t2[i][j]=akt;
		}
	}
	for(int j=0;j<=m;j++)
	{
		int akt=0;
		for(int i=0;i<=n;i++)
		{
			akt+=t2[i][j];
			t3[i][j]=akt;
		}
	}
	for(int j=1;j<=m;j++)
	{
		for(int i=1;i<=k;i++)
		{
			g[1][j]+=t3[i][j];
		}
		for(int i=2;i+k-1<=n;i++)
		{
			g[i][j]=g[i-1][j]+t3[i+k-1][j]-t3[i-1][j];
		}
	}
	int ans=0,ansi=-1,ansj=-1;
	for(int i=1;i+k-1<=n;i++)
	{
		int sum=0,psum=0;
		for(int j=1;j<=k;j++)psum+=g[i][j];
		if(psum>ans)
		{
			ans=psum;
			ansi=i+k-1;
			ansj=1;
		}
		for(int j=2;j+k-1<=m;j++)
		{
			sum=psum-g[i][j-1]+g[i][j+k-1];
			if(sum>ans)
			{
				ans=sum;
				ansi=i+k-1;
				ansj=j;
			}
			psum=sum;
		}
		
	}
	cout<<ans<<'\n'<<ansj<<" "<<(n+1)-ansi;
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/40
1Runtime error0/01ms1060 KiB
2Runtime error0/01ms1168 KiB
3Runtime error0/21ms1088 KiB
4Runtime error0/21ms1152 KiB
5Runtime error0/21ms1216 KiB
6Runtime error0/21ms1200 KiB
7Runtime error0/21ms1156 KiB
8Runtime error0/21ms1216 KiB
9Runtime error0/21ms1216 KiB
10Runtime error0/21ms1216 KiB
11Runtime error0/21ms1092 KiB
12Runtime error0/21ms1172 KiB
13Runtime error0/21ms1220 KiB
14Runtime error0/21ms1216 KiB
15Runtime error0/11ms1152 KiB
16Runtime error0/11ms1220 KiB
17Runtime error0/11ms1156 KiB
18Runtime error0/11ms1220 KiB
19Runtime error0/21ms1220 KiB
20Runtime error0/21ms1220 KiB
21Runtime error0/21ms1152 KiB
22Runtime error0/21ms1152 KiB
23Runtime error0/21ms1156 KiB
24Runtime error0/21ms1216 KiB