2612021-03-07 15:38:22varikakasandorSivatagcpp14Accepted 40/40298ms12680 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct rect
{
    ll bax,bay,jfx,jfy;
    rect(ll bax,ll bay,ll jfx,ll jfy) : bax(bax), bay(bay), jfx(jfx), jfy(jfy) {}
};

ll n,m,k,e;
vector<rect> rains;
ll best=-1;
ll bestx,besty;

int main()
{
    ios_base::sync_with_stdio(false);
    //freopen("Sivatag.txt","r",stdin);
    cin>>n>>m>>k>>e;
    for(ll i=1;i<=e;i++)
    {
        ll bax,bay,jfx,jfy;
        cin>>bax>>bay>>jfx>>jfy;
        rains.push_back(rect(bax,bay,jfx,jfy));
    }
    for(ll i=1;i<=n;i++)
    {
        ll xstart=i;
        ll xend=i+k-1;
        vector<ll> plusminus(m+2,0);
        for(rect r:rains)
        {
            if(max(xstart,r.bax)>min(xend,r.jfx)) continue;
            ll cover=min(xend,r.jfx)-max(xstart,r.bax)+1;
            plusminus[r.bay]+=cover;
            plusminus[r.jfy+1]-=cover;
        }
        vector<ll> perrow(m+1,0);
        vector<ll> pref(m+1,0);
        for(ll j=1;j<=m;j++) perrow[j]=perrow[j-1]+plusminus[j];
        for(ll j=1;j<=m;j++) pref[j]=pref[j-1]+perrow[j];
        for(ll j=1;j+k-1<=m;j++)
        {
            ll curr=pref[j+k-1]-pref[j-1];
            if(curr>best)
            {
                best=curr;
                bestx=i;
                besty=j;
            }
        }
    }
    cout<<best<<endl;
    cout<<bestx<<" "<<besty<<endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/02ms1760 KiB
2Accepted0/0261ms11180 KiB
3Accepted2/21ms3320 KiB
4Accepted2/22ms3324 KiB
5Accepted2/23ms3340 KiB
6Accepted2/23ms3344 KiB
7Accepted2/23ms3348 KiB
8Accepted2/23ms3352 KiB
9Accepted2/21ms3348 KiB
10Accepted2/22ms3352 KiB
11Accepted2/23ms3364 KiB
12Accepted2/23ms3372 KiB
13Accepted2/23ms3368 KiB
14Accepted2/23ms3376 KiB
15Accepted1/1221ms12652 KiB
16Accepted1/1282ms12672 KiB
17Accepted1/1136ms8532 KiB
18Accepted1/1209ms12672 KiB
19Accepted2/2298ms12676 KiB
20Accepted2/2273ms12672 KiB
21Accepted2/2286ms12680 KiB
22Accepted2/2296ms12676 KiB
23Accepted2/2280ms12672 KiB
24Accepted2/2275ms12676 KiB