9032022-01-26 14:10:44Babják PéterSivatagcpp11Runtime error 24/40101ms22200 KiB
#include <bits/stdc++.h>
#define MAXN 501
#define int long long
using namespace std;
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
base24/40
1Accepted0/02ms2024 KiB
2Runtime error0/06ms5932 KiB
3Accepted2/23ms4928 KiB
4Accepted2/24ms9028 KiB
5Accepted2/28ms15372 KiB
6Accepted2/28ms15396 KiB
7Accepted2/28ms15356 KiB
8Accepted2/28ms15376 KiB
9Accepted2/22ms4600 KiB
10Accepted2/24ms7712 KiB
11Accepted2/28ms14592 KiB
12Accepted2/28ms13660 KiB
13Wrong answer0/28ms13320 KiB
14Accepted2/27ms12552 KiB
15Accepted1/187ms12568 KiB
16Accepted1/1101ms17056 KiB
17Runtime error0/120ms9476 KiB
18Runtime error0/114ms9840 KiB
19Runtime error0/24ms9964 KiB
20Runtime error0/290ms19712 KiB
21Runtime error0/218ms11948 KiB
22Runtime error0/293ms22200 KiB
23Runtime error0/29ms13536 KiB
24Runtime error0/24ms13176 KiB