9042022-01-26 14:29:40Babják PéterSivatagcpp11Accepted 40/40108ms28056 KiB
#include <bits/stdc++.h>
#define MAXN 1005
#define int long long
using namespace std;
int n,m,k,e;
int t1[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];
			t1[i][j]=akt;
		}
	}
	for(int j=0;j<=m;j++)
	{
		int akt=0;
		for(int i=0;i<=n;i++)
		{
			akt+=t1[i][j];
			t1[i][j]=akt;
		}
	}

	for(int j=1;j<=m;j++)
	{
		for(int i=1;i<=k;i++)
		{
			g[1][j]+=t1[i][j];
		}
		for(int i=2;i+k-1<=n;i++)
		{
			g[i][j]=g[i-1][j]+t1[i+k-1][j]-t1[i-1][j];
		}
	}
	int ans=0,ansi=n,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
base40/40
1Accepted0/02ms1864 KiB
2Accepted0/093ms13216 KiB
3Accepted2/22ms5236 KiB
4Accepted2/24ms9304 KiB
5Accepted2/212ms19008 KiB
6Accepted2/225ms19016 KiB
7Accepted2/213ms19020 KiB
8Accepted2/213ms19032 KiB
9Accepted2/22ms4784 KiB
10Accepted2/23ms7320 KiB
11Accepted2/210ms17280 KiB
12Accepted2/28ms15564 KiB
13Accepted2/210ms14784 KiB
14Accepted2/28ms13244 KiB
15Accepted1/1108ms11900 KiB
16Accepted1/1103ms16868 KiB
17Accepted1/150ms22072 KiB
18Accepted1/182ms17904 KiB
19Accepted2/292ms21544 KiB
20Accepted2/297ms19776 KiB
21Accepted2/2101ms24352 KiB
22Accepted2/2101ms23836 KiB
23Accepted2/2101ms26876 KiB
24Accepted2/2101ms28056 KiB